贵金属策略--TestAu

来源:互联网 发布:iphone全景拼接软件 编辑:程序博客网 时间:2024/04/20 14:12

import java.util.Calendar;

public class Test {
public static void main(String[] args) {
printAvNum();

}
/**
* 持仓均值
*/
public static void printAvNum(){
//单价和数量一一对应,个数相同;数量=0.01的只在prices往右写,数量>0.01的即在prices往左写,也在counts往左写。
double[] prices = {1263.99,1238.77,1250.33,1282.71,1284.57,1285.81,1229};
double[] counts = {6};
//总结余
double jieYu = 1077.07;
//总值和总数量初始化;
double sum=0,countAll=0;
for(int i=0;i<prices.length;i++){
if(i<counts.length){
sum += prices[i]*counts[i];
countAll += counts[i];
}
else{
sum += prices[i];
countAll += 1;
}
}
double avNum = formatDouble(sum/countAll);
double lowPrice = avNum- (jieYu-countAll*55)/countAll;
System.out.println("持仓均值为:"+avNum);
System.out.println("持仓均值+5为:"+(avNum+5));
System.out.println("可用款为"+(int)countAll*50+"的底线价格为:"+formatDouble(lowPrice));
System.out.println("可用款为"+(int)countAll*40+"的底线价格为:"+formatDouble(lowPrice-10));
System.out.println("爆仓价为(仅有保证金,可用款为0):"+formatDouble(lowPrice-45));
}
/**
* 理论值ag
*/
public static double getAgPriceUSD(){
//获取当年年份;
Calendar cal = Calendar.getInstance();
int yearNow = cal.get(Calendar.YEAR);
//获取年增率;
float n = 15;
double root = Math.pow(1.365865,1/n);
// System.out.println((root-1)*100+"%");
//获取相对于基础年数2016的增加年数;
int yearNum = yearNow-2016;
//获取当前年份的理论基础值;
return 38.78*Math.pow(root,yearNum); 
}
/**
* 理论值au
*/
public static double getAuPriceUSD(){
//获取当年年份;
Calendar cal = Calendar.getInstance();
int yearNow = cal.get(Calendar.YEAR);
//获取年增率;
float n = 20;
double root = Math.pow(3.1134,1/n);
//获取相对于基础年数2016的增加年数;
int yearNum = yearNow-2016;
//获取当前年份的理论基础值;
return 1057*Math.pow(root,yearNum); 
}
/**
* 理论值au/CNH
*/
public static double getPriceCNH(){
double suggestedPriceAu = getAuPriceUSD();
System.out.println(suggestedPriceAu*278/1245);
return suggestedPriceAu*278/1245;
}
/**
     * 保留两位小数,四舍五入的方法
     */
public static double formatDouble(double d) {
        return (double)Math.round(d*100)/100;
    }


}



1 0