Enhancing Hands-on Learning using Mathematica: A case of Investment Analysis

Ramesh Adhikari,  Cal Poly HUmboldt

(RowDefault[, (Spacer1), , (Spacer1), ])  #WolframTechConf

ABSTRACT

Three important lessons to be aware of:

It’s hard to dismiss your grandma’s investment wisdom: don’t put all your eggs in one basket.

Avoid diving into the options markets unless you have a comprehensive understanding of them.

Consider micro-futures in your long-term portfolio.

Adhikari, R. (2020), “Foundations of Computational Finance”, The Mathematica Journal, Vol 22.  https://doi.org/10.3888/tmj.22-2

Adhikari, R. (2021), “Selected Financial Applications”, The Mathematica Journal, Vol 23.  https://doi.org/10.3888/tmj.23-5

NotebookEvaluate["C:\\Users\\rka102\\Desktop\\myfunctions.nb",InsertResults->True]

Don’t put all your eggs in one basket.

There are thousands of stocks traded in North America across various stock exchanges. High performing stocks (DXCM, NVDA, ISRG,NFLX,TSLA ) vs worst performing stocks (ONTX, WNW,TRIX). Volatile Stocks (ROKU, ZOOM, MRNA).

performanceOfOneSymbol["MRNA",{2021,01,01},{2023,10,30},"Day"]

monthlyOneStockStatitics["WNW",{2020,01,1},{2023,10,30},Total]

Don’t put all your eggs in one basket.

Comparing Performance of Different Stocks

Lets look at performance of different stocks.

performanceStatisticsTable[{"TSLA","ISRG","NVDA"},{2020,03,20},{2023,10,30},"Month"]//Text

Lets Understand Call Option

Manipulate[Grid[{{Style["Call Price",40]},{Style[FinancialDerivative[{"American","Call"},{"StrikePrice"->K,"Expiration"->T},{"InterestRate"->rf,"Volatility"->σ,"CurrentPrice"->S0,"Dividend"->δ}],40]}},Frame->All,Background->{Green,{Pink}}],Style["Determinants of Option Price",Bold,Underlined,20,Blue],{{K,40,Style["Strike Price",20,Bold,Red]},40,60,Appearance->{"Labeled","Open"}},{{T,1,Style["Time To Expiration",20,Bold,Red]},1,2,Appearance->{"Labeled","Open"}},{{rf,0.01,Style["Interest Rate",20,Bold,Red]},0.01,0.1,Appearance->{"Labeled","Open"}},{{σ,0.1,Style["Voltality",20,Bold,Red]},0.1,5,Appearance->{"Labeled","Open"}},{{S0,40,Style["Current Price",20,Bold,Red]},40,80,Appearance->{"Labeled","Open"}},{{δ,0,Style["Dividend",20,Bold,Red]},0,0.1,Appearance->{"Labeled","Open"}},ControlPlacement->Left]

Lets Understand Put Option

Manipulate[Grid[{{Style["Put Price",40]},{Style[FinancialDerivative[{"American","Put"},{"StrikePrice"->K,"Expiration"->T},{"InterestRate"->rf,"Volatility"->σ,"CurrentPrice"->S0,"Dividend"->δ}],40]}},Frame->All,Background->{Green,{Pink}}],Style["Determinants of Option Price",Bold,Underlined,20,Blue],{{K,40,Style["Strike Price",20,Bold,Red]},40,60,Appearance->{"Labeled","Open"}},{{T,1,Style["Time To Expiration",20,Bold,Red]},1,2,Appearance->{"Labeled","Open"}},{{rf,0.01,Style["Interest Rate",20,Bold,Red]},0.01,0.1,Appearance->{"Labeled","Open"}},{{σ,0.1,Style["Voltality",20,Bold,Red]},0.1,5,Appearance->{"Labeled","Open"}},{{S0,40,Style["Current Price",20,Bold,Red]},40,80,Appearance->{"Labeled","Open"}},{{δ,0,Style["Dividend",20,Bold,Red]},0,0.1,Appearance->{"Labeled","Open"}},ControlPlacement->Left]

Let’s Find Option Value and Greeks for a Stock

The built-in Mathematica function FinancialDerivative computes the values and other price sensitivity measures for common types of derivative contracts. The function can compute the value of an option, any of delta, gamma, theta and vega, as well as the implied volatility of the contract.

Grid[
computeOptionParameters["BA",220,{2024,10,28},0.0187,"European"],
Frame->All]//Text

Futures Markets: Price Ticks and Point Values of Equity Indices

Let’s Historical Futures Values

We can use ES for S&P 500 index futures, NQ for Nasdaq 100 futures, RTY for Russell 200 futures, GC for gold futures, and CL for crude oil futures. The start data and end date should be specified in the function.

mydata=getmyfuturedata["ES"];

partmydata=TimeSeriesWindow[mydata,{{2020,1,1},{2023,10,30}}];
TradingChart[partmydata]

partmydata2=TimeSeriesWindow[mydata,{{2021,1,1},{2023,10,30}}];
InteractiveTradingChart[partmydata2,{"RelativeStrengthIndex"}]

pointValue=2;
begValue=700;
endValue=16000;
beginingNotionalValue=pointValue*begValue;
margin=0.12;
initialInvestment=margin*beginingNotionalValue;
"Initival Capital needed for One Contract"<>"= $"<>ToString[initialInvestment]
totalchange=endValue-begValue;
dollargain=pointValue*totalchange;
"Gross Returns"<>"= $"<>ToString[dollargain]
profitPercent=ToString[100*(dollargain/initialInvestment-1)//N]<>"%"

Conclusions

While there are wide range of software available for modelling and analysis of financial data, Mathematica is the best in its kind because of its rich set of built in functions especially designed for analysis of financial data, both for exploratory data analysis and fitting statistical models.

The functions we have provided are just a few examples. Mathematica can do much more that what we have shown in here.
Interested readers can start exploring Mathematica using its extensive documentation.