# Multi-Asset Value at Risk?

**URL:** <https://community.wolfram.com/t/multi-asset-value-at-risk/242>\
**Category:** Questions\
**Tags:** finance\
**Created:** [July 15, 2013, 11:55am UTC](https://community.wolfram.com/t/multi-asset-value-at-risk/242 "2013-07-15T11:55:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![martinh](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/martinh/32/37239_2.png) [@martinh](https://community.wolfram.com/u/martinh)\
**Post date:** [July 15, 2013, 11:55am UTC](https://community.wolfram.com/t/multi-asset-value-at-risk/242/1 "2013-07-15T11:55:23Z")

</div>

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..

```auto
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](http://www.math.nus.edu.sg/~urops/Projects/valueatrisk.pdf) amongst other resources and built the following function:

```auto
 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:

```auto
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.
