• ###### Marty3000commented on "Advanced binary toggling puzzle" kata

i think that carloscerro is right.

The valuation-test seems to rely on an unchanged input variable.

please check the following code. It will fail for the first basic test (One toggle), but will succeed if you out-commend the lines 2 and 3:

``````def solve(puzzle):
if 0 < len(puzzle):
puzzle = (puzzle + 1) % 2
return [(1, 1)]
``````
• ###### Marty3000commented on "Value at Risk for an equity portfolio" kata

Hi Reswin,

thanks for the feedback.
In fact, uttumuttu did a good job and seems to be very clever in general.

PS:
This kind of approach ( using past or self-defined relative shifts for the risk-factors ) is not only used to calculate Vaule-at-Risk, but also other by risk-measures like "expected shortfall", or scenarios ( e.g. black friday ) or sensitivities ( checking how much win/loss e.g. a yield shift of 1% would induce ).

• ###### Reswincommented on "Value at Risk for an equity portfolio" kata

@uttumuttu's second suggestion to describe VAR was helfpul for me: "The simplest explanation (of VAR) is that each equity's total shifts are obtained as the relative shifts of its currency-converted price series." I enjoyed the kata because it not only allowed me to practice Python but also to learn about VAR.

• ###### Marty3000commented on "Value at Risk for an equity portfolio" kata

Sorry have written, before thinking:

VAR is not sub-additive in both dimensions ( over Risk-Classes and over sub-Positions ).

Will modify th desciption accordingly.

• ###### Marty3000commented on "Value at Risk for an equity portfolio" kata

Hi uttumttu,

thanks a lot for your input.
Since i am very new to writing kata, i do need some help indeed.
It's in fact a thin line between spoiling too much of the algorythm/implementation or potentially frustrate someone trying to solve it.

i don't know, if that is common practise, but feel free to apply some your suggestions to the description, as well.

I added the following section ( it's near the end ), but i do get the feeling, that the whole kata description may be too long now ( distracting interested people ) for such a relative simple calculation :

We had no Forex risk involved in this example, since the equity was listed in your base-currency.
Please ensure that the shifts of the foreign currency are taken into account, as well, when calculating the 'Total'-VAR for a foreign-currency-equity-positions.

You then might notice some kind of strange behaviour of your VAR-results:

So neither

``````total VAR = equity VAR + currency VAR
``````

nor

``````VAR(EQ_all) = VAR(EQ1) + VAR(EQ2)
for an Equity position EQ_all that consists fo Equity position 1 ( EQ1 ) + Equity position 2 ( EQ2 )
``````

In fact, the VAR for a given position might be lower or equal than the sum of the VAR of it's parts.

When looking at the different Riskclasses, it's even 'worse': The total-VAR can be lower, equal or bigger than the sum of equity-VAR and currency-VAR.

Keep in mind, that the Value-at-Risk measurement is based on the potential top losses (relative shifts) only. And these top losses ( for individual equities or riskclasses ) may have occurred on different historical days ( for the equities/riskclasses ) involved.

• ###### uttumuttucreated a suggestion for "Value at Risk for an equity portfolio" kata

Two suggestions related to the issues faced by Reswin, aimed to make the kata more accessible to people without a quantitative finance background:

1. The non-additive nature of VAR could be incorporated into the description. That is, the reader should understand that they are to first construct the daily gain-loss distribution summed across equities, and only then calculate the quantile.

2. Calculation of total (equity plus currency) shifts could be described more clearly. The simplest explanation is that each equity's total shifts are obtained as the relative shifts of its currency-converted price series. An even simpler alternative is to simply spell out the geometric compounding formula (or, less spoilerly, the equations leading to it), which is equivalent but easier to code on top of existing equity and currency shifts calculated by `get_shift`).

• ###### Marty3000commented on "Value at Risk for an equity portfolio" kata

Hi Reswin,

thanks for the hint.
i did add the provided and the expected results for teh large randomized tests.

• ###### Reswincommented on "Value at Risk for an equity portfolio" kata

Hi Marty,
this was very helpful, thank you. My solution now passes all the description related tests and most of the random larger tests. The output I am getting for the failed tests is "False should equal True", which does not help me in finding my error(s). Would it be possible to change this to something like: "get_var is returning incorrect value: 96.02 should equal 104.89"?

• ###### Marty3000commented on "Value at Risk for an equity portfolio" kata

Hi Reswin,

VAR is not additive ( not over the different assets, nor for the different risk-classes).
You cannot calculate the VAR for one Equity(-position) and then add another.
You have to calculate the potential, relative shifts (based on the history) for your whole position, and then (sort and) calculate the VAR for the whole position.

(i marked the first comment as a spoiler. That's why it is "hidden")

• ###### Reswincommented on "Value at Risk for an equity portfolio" kata

I could solve my problem with rounding: I rounded past relative shifts to 6 digits because you wrote you rounded them to 6 digits (for better readability). I can pass the tests if I don't round.

I am still struggling with how VAR is calculated, except for the simple cases where only one equity is involved.

@Marty3000: I cannot see your comment, you seem to have hidden it.

• ###### Marty3000resolved an issue on "Value at Risk for an equity portfolio" kata

Your're awesome ( and that's not only a lame joke ).
description is updated.

• ###### awesomeadcreated an issue for "Value at Risk for an equity portfolio" kata

There is an error in the description, specifically in the example for past relative shifts:

``````[0.044444, -0.010638, -0.021505, -0.010989, 0.111111, 0.04, -0.009615, -0.019417, -0.019802, 0.0]
Error ^
``````

That last item should be `0.010101`. It is correct in the sample tests, but not in the description.

• ###### Marty3000commented on "Value at Risk for an equity portfolio" kata

This comment is hidden because it contains spoiler information about the solution

• ###### Reswincommented on "Value at Risk for an equity portfolio" kata

I am having two issues:

(1) I seem to have a problem with rounding, as I am getting this error message in the tests: "1-Day Equity Value at Risk for your 100 MartyCorp - Equities and a confidence level of 0.90 is 206.54 USD: 206.53 should equal 206.54"

(2) It's not clear to me how to calculate total VAR for equtiy and foreign exchange risk. For each day I calculate the value shift due to the change in equity rates and the change in foreign exchange rate and I then add the two amounts.
I am enjoying this kata and would appreciate a hint so that I can finish it.

• ###### Marty3000commented on "Value at Risk for an equity portfolio" kata

Shame on me,
thanks for point out these issues.

Should be fixed, now.