⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buyandhold.java

📁 金融资产定价,随机过程,MONTE CARLO 模拟 JAVA 程序和文档资料
💻 JAVA
字号:
/* WARANTY NOTICE AND COPYRIGHTThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.Copyright (C) Michael J. Meyermatmjm@mindspring.comspyqqqdia@yahoo.com*//* * BuyAndHold.java * * Created on March 12, 2002, 11:54 PM */package Examples.Trading;import Statistics.*;import Market.*;import TradingStrategies.*;import Triggers.*;import java.lang.Math;/** <p>Console program allocating a constant volatility asset and examining *  the buy and hold strategy. 100 shares are bought at time t=0 and held to  *  the horizon. Computes the means and standard deviations of:</p>  * *<ul> * <li>the gains from trading</li> * <li>the maximum amount borrowed</li> * <li>the maximum drawdown</li> * <li>the annualized return on investment (compounded continuously)</li> * <li>the number of trades</li> * </ul> * * <p>All except the last quantity are discounted amounts and all are evaluated  * at the time horizon T. * Parameters (time to expiration, volatility,...) fixed in source code. * No user interaction. 10,000 paths of the underlying asset are simulated.</p> *  * @author  Michael J. Meyer * */public class BuyAndHold{  public static void main(String[] args)  {            int  T=50,           nPaths=10000,           nSignChange=5;    // irrelevant but needed for asset constructor                   double S_0=50,             mu=0.24,             sigma=0.31,             q=0.05,             r=0.07,             dt=0.02,             fixed_trc=0.0,   // fixed transaction costs             prop_trc=0.0;   // proportional transaction costs                                 ConstantVolatilityAsset       asset=new ConstantVolatilityAsset(T,dt,nSignChange,S_0,r,q,mu,sigma);              TradingStrategy        buyAndHold=new StrategyBuyAndHold(fixed_trc,prop_trc,asset);                     /* the statistics associated with this strategy:        * mean and variance of five quantities:        * the gains from trading, maximum borrowings,        * maximum drawdown, amount invested at time T,        * return on investment.        *        * Recall: vector of means is stats[0][.]        *         vector of standard deviations is stats[1][.]        */       double[][] stats=buyAndHold.tradeStatistics().                        meanAndStandardDeviation(nPaths);              // report the results:       String message;       message=       "Asset: S(0)="+S_0+", mu="+mu+", sigma="+sigma+"\n"+       "Investor buys 100 shares and holds to horizon T="+T*dt+" years.\n"+       "Initial investment: "+buyAndHold.initialInvestment()+"\n\n";              System.out.println(message);                     double mean, stdv;              //gains from trading:       mean=stats[0][0];       stdv=stats[1][0];       mean=1.0*Math.round(10000*mean)/10000;   //cut down to 5 decimals       stdv=1.0*Math.round(10000*stdv)/10000;   //cut down to 5 decimals              message=       "Gains from trading:\n"+       "Mean="+mean+",  standard deviation="+stdv+"\n\n";              System.out.println(message);                     // maximum amount borrowed:       mean=stats[0][1];       stdv=stats[1][1];       mean=1.0*Math.round(10000*mean)/10000;   //cut down to 5 decimals       stdv=1.0*Math.round(10000*stdv)/10000;   //cut down to 5 decimals              message=       "Maximum amount borrowed:\n"+       "Mean="+mean+",  standard deviation="+stdv+"\n\n";              System.out.println(message);                     //maximum drawdown:       mean=stats[0][2];       stdv=stats[1][2];       mean=1.0*Math.round(10000*mean)/10000;   //cut down to 5 decimals       stdv=1.0*Math.round(10000*stdv)/10000;   //cut down to 5 decimals              message=       "Maximum drawdown:\n"+       "Mean="+mean+",  standard deviation="+stdv+"\n\n";              System.out.println(message);                     //return on investment at time T:       mean=stats[0][3];       stdv=stats[1][3];       mean=1.0*Math.round(10000*mean)/10000;   //cut down to 5 decimals       stdv=1.0*Math.round(10000*stdv)/10000;   //cut down to 5 decimals              message=       "Return on investment:\n"+       "Mean (should be "+mu+")="+mean+"\n"+       "Standard deviation (should be "+sigma+")="+stdv+"\n\n";              System.out.println(message);         }//end main   }//end BuyAndHold        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -