Data formatting - Volatility and return columns.

4 ビュー (過去 30 日間)
Andrew Czeizler
Andrew Czeizler 2019 年 3 月 20 日
コメント済み: Andrew Czeizler 2019 年 3 月 21 日
Hi All,
I need some help building a datase of financial data to use in experiments.
I need the daily and return and daily volatility of columns of symbols i download.
First attempt is below. The loop works but I'm not sure how proceed with creating columns of daily
return and volatility.
Many thanks,
Best,
Andrew
symbols = {'^GSPC', 'DAX', '^N225', 'GLD', 'QQQ'};
for i = 1:length(symbols)
symbols{i} = table2timetable(F_Alphavantage('time_series_daily_adjusted', 'symbol',...
symbols{i}, 'outputsize', 'full'));
end
TT= synchronize(symbols{1}, symbols{2}, symbols{3}, symbols{4}, symbols{5})
TT = rmmissing(TT)
returnFunc = @(open,high,low,close,volume) (close) - (open);
weeklyReturn = rowfun(returnFunc,symbols{1},'OutputVariableNames',{'Return'});
weeklyStd = retime(symbols{1}(:,'Close'));
weeklyStd.Properties.VariableNames{'Close'} = 'Volatility';
  1 件のコメント
Andrew Czeizler
Andrew Czeizler 2019 年 3 月 21 日
I have an update on my attempt to add volatility and return column. Still dont know how to get seperate tables for each symbol with the return and volatility column.
Any help would be very much appreciated.
Best,
Andrew
symbols = {'^GSPC', 'DAX', '^N225', 'GLD', 'QQQ'};
for i = 1:length(symbols)
symbols{i} = table2timetable(F_Alphavantage('time_series_daily_adjusted', 'symbol',...
symbols{i}, 'outputsize', 'full'));
end
returnFunc = @(open,high,low,close,volume) log(close) - log(open);
for i=1:length(symbols)
weeklyOpen{i} = retime(symbols{i}(:,'Open'),'daily','firstvalue');
weeklyHigh{i} = retime(symbols{i}(:,'High'),'daily','max');
weeklyLow{i} = retime(symbols{i}(:,'Low'),'daily','min');
weeklyClose{i} = retime(symbols{i}(:,'Close'),'daily','lastvalue');
weeklyTMW{i} = [weeklyOpen,weeklyHigh,weeklyLow,weeklyClose];
weeklyTMW{i} = synchronize(weeklyTMW,symbols{i}(:,'Volume'),'daily','sum');
weeklyReturn{i} = rowfun(returnFunc,weeklyTMW,'OutputVariableNames',{'Return'});
weeklyStd{i} = retime(symbols{i}(:,'Close'),'daily',@std);
weeklyStd.Properties.VariableNames{'Close'} = 'Volatility';
weeklyTMW{i} = [weeklyReturn,weeklyStd,weeklyTMW];
end

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeDevice Characteristics Assessment についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by