Message Boards Message Boards

5
|
3454 Views
|
0 Replies
|
5 Total Likes
View groups...
Share
Share this post:
GROUPS:

Multi-Asset Value at Risk?

Posted 11 years ago
I've been demonstrating how Wolfram Finance Platform could be used for Value at Risk (VaR) for a while now, but have only been showing single asset calculations like the following and then show EmpiricalDistribution, CombinedDistribution, etc..
InverseSurvivalFunction[EstimatedDistribution[FinancialData["AAPL", "Return", DatePlus[-365], "Value"],NormalDistribution[a, b]],0.95]

But that's quite boring, so I've looked around for a guide to portfolio VaR measurements and found this http://www.math.nus.edu.sg/~urops/Projects/valueatrisk.pdf amongst other resources and built the following function:
  multiAssetVaR[stocks_List, weights_List, buyDate_List, 
   estDist_: NormalDistribution[](*If no other distribution specified, 
   normal assumed*), conf_: 0.95(*risk level, default 0.95*)] := 
  Module[{initialPrices, currentPrices, ratesOfReturn, rateWeights, 
    portRateOfReturn, stockReturns, varPortRateOfReturn, multiAssetVaR},  
   initialPrices = 
    Transpose[{Flatten[
       ParallelMap[
        FinancialData[#[[1]], "Price", {#[[2]]}, "Value"] &, {stocks, 
         buyDate} // Transpose]], weights}];  
  currentPrices = 
   Transpose[{ParallelMap[FinancialData[#, "Price"] &, stocks], 
     weights}];  
  ratesOfReturn = 
   Map[(Times @@ #[[2]] - Times @@ #[[1]])/Times @@ #[[1]] &, 
    Transpose[{initialPrices, currentPrices}]];  
  rateWeights = 
   Map[Times @@ #/Total[Times @@@ currentPrices] &, currentPrices];  
  portRateOfReturn = Total[Times @@@ {rateWeights, ratesOfReturn}];  
  stockReturns = 
   ParallelMap[
    FinancialData[#[[1]], "Return", {#[[2]], Date[]}, "Value"] &, 
    Transpose[{stocks, buyDate}]];  
  varPortRateOfReturn = 
   rateWeights.Covariance[
     Transpose[stockReturns]].Transpose[{rateWeights}];
  multiAssetVaR = (InverseSurvivalFunction[estDist, conf]*(-1))*
    Sqrt[varPortRateOfReturn]
  ]

Usage:
multiAssetVaR[{"LLOY.L", "BARC.L", "RBS.L"}, {2000, 1423, 1000}, {{2012, 11, 1}, {2012, 11, 1}, {2012, 11, 1}}]


I've only limited experience with actually applying financial models, could anyone advise whether what I've done is appropiate?

Comments on the code would also be appreciated, I used ParallelMap for FinancialData calls to reduce the lag in collecting data (my birthday was chosen for the purchase dates at DayOfWeek told me it was a Thursday) but have assumed parallelisation is not beneficial for the rest of the maps. Note that if I had a Bloomberg subscription myself then I'd use BloombergLink, but at the moment I just have FinancialData.
POSTED BY: Martin Hadley
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract