You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On the homepage it is described how you can use the diff method on a series to calculate the daily returns from a series of prices Link to homepage
I think that example is wrong - you write "To calculate daily returns, we need to subtract the price on previous day from the price on the current day. This is done by using the Diff extension method (another option is to use Shift together with the overloaded subtraction operator). Then we divide the difference by the current price and multiply the result by 100.0 to get value in percents."
This gives the formula:
(CurrentPrice - PreviousPrice) / CurrentPrice
But this is wrong the formula should be:
(CurrentPrice - PreviousPrice) / PreviousPrice As described on wikipedia
The code on the homepage looks like this: var returns = msft.Diff(1) / msft * 100.0;
But should be like this (assuming the key is a DateTime): var returns = msft.Diff(1) / msft.SelectKeys(x => x.Key.AddDays(1) * 100.0;
The text was updated successfully, but these errors were encountered:
@zyzhu I found a more elegant way to calculate the return/pct change:
var returns = msft.Diff(1) / msft.Shift(1) * 100;
It could be useful to have a built in function called PctChange (like pandas pct_change)
On the homepage it is described how you can use the diff method on a series to calculate the daily returns from a series of prices Link to homepage
I think that example is wrong - you write "To calculate daily returns, we need to subtract the price on previous day from the price on the current day. This is done by using the Diff extension method (another option is to use Shift together with the overloaded subtraction operator). Then we divide the difference by the current price and multiply the result by 100.0 to get value in percents."
This gives the formula:
(CurrentPrice - PreviousPrice) / CurrentPrice
But this is wrong the formula should be:
(CurrentPrice - PreviousPrice) / PreviousPrice
As described on wikipedia
The code on the homepage looks like this:
var returns = msft.Diff(1) / msft * 100.0;
But should be like this (assuming the key is a DateTime):
var returns = msft.Diff(1) / msft.SelectKeys(x => x.Key.AddDays(1) * 100.0;
The text was updated successfully, but these errors were encountered: