伦敦金策略--TestAu

xiaoxiao2021-02-28  132

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;     } }
转载请注明原文地址: https://www.6miu.com/read-19451.html

最新回复(0)