PLearn 0.1
|
#include <FinancePreprocVMatrix.h>
Public Member Functions | |
FinancePreprocVMatrix () | |
a row buffer for the getRow method | |
FinancePreprocVMatrix (VMat the_source, TVec< string > the_asset_names, bool add_tradable_info=true, bool add_last_day=false, bool add_moving_average_stats=false, bool add_roll_over_info=false, int threshold=20, TVec< string > the_price_tags=TVec< string >(), TVec< int > moving_average_window_length=TVec< int >(), string the_volume_tag="volume:level", string the_date_tag="Date", string the_expiration_tag="expiration-date", int the_last_day_cutoff=0, bool last_date_is_a_last_day=false) | |
Simple constructor: takes as input only the source matrix, the number of assets and the threshold on the volume. | |
virtual void | build () |
Simply calls inherited::build() then build_(). | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual FinancePreprocVMatrix * | deepCopy (CopiesMap &copies) const |
Static Public Member Functions | |
static string | _classname_ () |
Declares name and deepCopy methods. | |
static OptionList & | _getOptionList_ () |
static RemoteMethodMap & | _getRemoteMethodMap_ () |
static Object * | _new_instance_for_typemap_ () |
static bool | _isa_ (const Object *o) |
static void | _static_initialize_ () |
static const PPath & | declaringFile () |
Public Attributes | |
TVec< string > | asset_name |
bool | add_tradable |
all the asset names | |
bool | add_last_day_of_month |
do we include the information about the last tradable day of the month | |
bool | add_moving_average |
do we include the moving average statistics on the price_tag indexes | |
bool | add_rollover_info |
add a column with '1' when the rollover occur (new expiration date) | |
int | min_volume_threshold |
tradable = 1 if volume>min_volume_threshold | |
TVec< string > | prices_tag |
all the price tags on which we want to compute the moving average (e.g. | |
TVec< int > | moving_average_window |
the window size of the moving average | |
string | volume_tag |
string | date_tag |
"volume" by default | |
string | expiration_tag |
"expiration-date" by default. Only used if add_rollover_info==true | |
int | last_day_cutoff |
0 by default (last day of month). | |
bool | last_date_is_last_day |
is the last day a last day of month? (default=false) | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
void | setVMFields () |
virtual void | getNewRow (int i, const Vec &v) const |
Must be implemented in subclasses: default version returns an error. | |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Protected Attributes | |
TVec< int > | volume_index |
the indexes (in the vmat) of all the volume columns | |
TVec< int > | price_index |
the indexes of all the prices on which we want to compute some stats | |
TVec< int > | expiration_index |
the index of the expiration-date (related to the expiration_tag) | |
Vec | last_day_of_month_index |
the index of all the last tradable day of the month, base on the date column of the source matrix | |
int | max_moving_average_window |
the maximum value of moving_average_window | |
TVec< TVec< int > > | rollover_date |
Vec | row_buffer |
the position (date) of all rollover | |
Private Types | |
typedef SourceVMatrix | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 50 of file FinancePreprocVMatrix.h.
typedef SourceVMatrix PLearn::FinancePreprocVMatrix::inherited [private] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file FinancePreprocVMatrix.h.
PLearn::FinancePreprocVMatrix::FinancePreprocVMatrix | ( | ) |
a row buffer for the getRow method
Definition at line 54 of file FinancePreprocVMatrix.cc.
:inherited(), add_tradable(false), add_last_day_of_month(false), add_moving_average(false), add_rollover_info(false) {}
PLearn::FinancePreprocVMatrix::FinancePreprocVMatrix | ( | VMat | the_source, |
TVec< string > | the_asset_names, | ||
bool | add_tradable_info = true , |
||
bool | add_last_day = false , |
||
bool | add_moving_average_stats = false , |
||
bool | add_roll_over_info = false , |
||
int | threshold = 20 , |
||
TVec< string > | the_price_tags = TVec<string>() , |
||
TVec< int > | moving_average_window_length = TVec<int>() , |
||
string | the_volume_tag = "volume:level" , |
||
string | the_date_tag = "Date" , |
||
string | the_expiration_tag = "expiration-date" , |
||
int | the_last_day_cutoff = 0 , |
||
bool | last_date_is_a_last_day = false |
||
) |
Simple constructor: takes as input only the source matrix, the number of assets and the threshold on the volume.
Definition at line 59 of file FinancePreprocVMatrix.cc.
References build().
:inherited(the_source, the_source->length(), the_source->width() + (add_tradable_info?the_asset_names.size():0) + (add_last_day?1:0) + (add_moving_average_stats?the_asset_names.size()*the_price_tags.size()*moving_average_window_length.size():0) + (add_roll_over_info?the_asset_names.size():0)), asset_name(the_asset_names), add_tradable(add_tradable_info), add_last_day_of_month(add_last_day), add_moving_average(add_moving_average_stats), add_rollover_info(add_roll_over_info), min_volume_threshold(threshold), prices_tag(the_price_tags), moving_average_window(moving_average_window_length), volume_tag(the_volume_tag), date_tag(the_date_tag), expiration_tag(the_expiration_tag), last_day_cutoff(the_last_day_cutoff), last_date_is_last_day(last_date_is_a_last_day), rollover_date(asset_name.size()), row_buffer(the_source->width()) { build(); }
string PLearn::FinancePreprocVMatrix::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file FinancePreprocVMatrix.cc.
OptionList & PLearn::FinancePreprocVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file FinancePreprocVMatrix.cc.
RemoteMethodMap & PLearn::FinancePreprocVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file FinancePreprocVMatrix.cc.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file FinancePreprocVMatrix.cc.
Object * PLearn::FinancePreprocVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file FinancePreprocVMatrix.cc.
StaticInitializer FinancePreprocVMatrix::_static_initializer_ & PLearn::FinancePreprocVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file FinancePreprocVMatrix.cc.
void PLearn::FinancePreprocVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::SourceVMatrix.
Definition at line 341 of file FinancePreprocVMatrix.cc.
References PLearn::SourceVMatrix::build(), and build_().
Referenced by FinancePreprocVMatrix().
{ inherited::build(); build_(); }
void PLearn::FinancePreprocVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 250 of file FinancePreprocVMatrix.cc.
References add_last_day_of_month, add_moving_average, add_rollover_info, add_tradable, PLearn::TVec< T >::append(), asset_name, date_tag, expiration_index, expiration_tag, i, PLearn::is_equal(), PLearn::is_missing(), j, last_date_is_last_day, last_day_cutoff, last_day_of_month_index, PLearn::VMat::length(), PLearn::VMatrix::length_, PLearn::max(), max_moving_average_window, moving_average_window, price_index, prices_tag, PLearn::TVec< T >::resize(), rollover_date, PLearn::VMatrix::saveFieldInfos(), PLearn::SourceVMatrix::setMetaInfoFromSource(), setVMFields(), PLearn::TVec< T >::size(), PLearn::SourceVMatrix::source, PLearn::VMatrix::updateMtime(), volume_index, volume_tag, PLearn::VMat::width(), and PLearn::VMatrix::width_.
Referenced by build().
{ if(length_ == -1 || width_ == -1) { length_ = source->length(); width_ = ( source->width() + (add_tradable?asset_name.size():0) + (add_last_day_of_month?1:0) + (add_moving_average?asset_name.size()*prices_tag.size()*moving_average_window.size():0) + (add_rollover_info?asset_name.size():0) ); updateMtime(source); } // stuff about the tradable information int nb_assets = asset_name.size(); if (add_tradable) { volume_index.resize(nb_assets); for (int i=0; i<nb_assets; i++) { string volume_name_col = asset_name[i]+":"+volume_tag; volume_index[i] = source->fieldIndex(volume_name_col); } } if (add_last_day_of_month) { int date_col = source->fieldIndex(date_tag); int julian_day = int(source->get(0,date_col)); PDate first_date(julian_day-last_day_cutoff); int previous_month = first_date.month; for (int i=1; i<source.length(); i++) { julian_day = int(source->get(i,date_col)); PDate today(julian_day-last_day_cutoff); int this_month = today.month; if (this_month != previous_month) last_day_of_month_index.append(i-1); previous_month = this_month; } // if needed, we set the last day as a last tradable day of month if (last_date_is_last_day) last_day_of_month_index.append(source.length()-1); } if (add_moving_average) { max_moving_average_window = max(moving_average_window); int price_index_size = nb_assets*prices_tag.size(); price_index.resize(price_index_size); int k = 0; for (int i=0; i<nb_assets; i++) { for (int j=0; j<prices_tag.size(); j++) { string moving_average_name_col = asset_name[i]+":"+prices_tag[j]; price_index[k++] = source->fieldIndex(moving_average_name_col); } } } if (add_rollover_info) { expiration_index.resize(nb_assets); for (int i=0; i<nb_assets; i++) { string expiration_name_col = asset_name[i]+":"+expiration_tag; expiration_index[i] = source->fieldIndex(expiration_name_col); rollover_date[i].resize(0); real last_expiration_date = source->get(0,expiration_index[i]); for (int j=1; j<source.length(); j++) { real expiration_date = source->get(j,expiration_index[i]); if (!is_missing(expiration_date) && !is_equal(expiration_date, last_expiration_date)) { if (!is_missing(last_expiration_date)) rollover_date[i].append(j); last_expiration_date = expiration_date; } } } } setVMFields(); saveFieldInfos(); setMetaInfoFromSource(); }
string PLearn::FinancePreprocVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file FinancePreprocVMatrix.cc.
void PLearn::FinancePreprocVMatrix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 141 of file FinancePreprocVMatrix.cc.
References add_last_day_of_month, add_moving_average, add_rollover_info, add_tradable, PLearn::OptionBase::buildoption, date_tag, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), expiration_tag, last_day_cutoff, PLearn::OptionBase::learntoption, min_volume_threshold, moving_average_window, PLearn::OptionBase::nosave, prices_tag, PLearn::SourceVMatrix::source, and volume_tag.
{ declareOption(ol, "vmat", &FinancePreprocVMatrix::source, (OptionBase::learntoption | OptionBase::nosave), "DEPRECATED - use 'source' instead."); declareOption(ol, "add_tradable", &FinancePreprocVMatrix::add_tradable, OptionBase::buildoption, "Do we include the information telling if this day is" " tradable or not."); declareOption(ol, "add_last_day_of_month", &FinancePreprocVMatrix::add_last_day_of_month, OptionBase::buildoption, "Do we include the information about the last tradable day" " of the month or not."); declareOption(ol, "add_moving_average", &FinancePreprocVMatrix::add_moving_average, OptionBase::buildoption, "Do we include the moving average statistics on the" " price_tag indexes."); declareOption(ol, "add_rollover_info", &FinancePreprocVMatrix::add_rollover_info, OptionBase::buildoption, "Do we include the boolean information on whether or not\n" "this is a new time series (new expiration date).\n"); declareOption(ol, "min_volume_threshold", &FinancePreprocVMatrix::min_volume_threshold, OptionBase::buildoption, "The threshold saying if the asset is tradable or not."); declareOption(ol, "moving_average_window", &FinancePreprocVMatrix::moving_average_window, OptionBase::buildoption, "The window size of the moving average."); declareOption(ol, "prices_tag", &FinancePreprocVMatrix::prices_tag, OptionBase::buildoption, "The fieldInfo name for the prices columns."); declareOption(ol, "volume_tag", &FinancePreprocVMatrix::volume_tag, OptionBase::buildoption, "The fieldInfo name for the volume column."); declareOption(ol, "date_tag", &FinancePreprocVMatrix::date_tag, OptionBase::buildoption, "The fieldInfo name of the date column."); declareOption(ol, "expiration_tag", &FinancePreprocVMatrix::expiration_tag, OptionBase::buildoption, "The fieldInfo name of the expiration-date column."); declareOption(ol, "last_day_cutoff", &FinancePreprocVMatrix::last_day_cutoff, OptionBase::buildoption, "Cutoff for the add_last_day_of_month flag (default=0)."); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::FinancePreprocVMatrix::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 168 of file FinancePreprocVMatrix.h.
FinancePreprocVMatrix * PLearn::FinancePreprocVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file FinancePreprocVMatrix.cc.
Must be implemented in subclasses: default version returns an error.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 87 of file FinancePreprocVMatrix.cc.
References add_last_day_of_month, add_moving_average, add_rollover_info, add_tradable, asset_name, PLearn::TVec< T >::contains(), PLearn::TVec< T >::find(), PLearn::is_missing(), j, last_day_of_month_index, PLearn::TVec< T >::length(), MAX, max_moving_average_window, PLearn::mean(), MIN, min_volume_threshold, moving_average_window, price_index, prices_tag, rollover_date, row_buffer, PLearn::TVec< T >::size(), PLearn::SourceVMatrix::source, PLearn::TVec< T >::subVec(), volume_index, and PLearn::VMat::width().
{ Vec row_buffer = v.subVec(0, source.width()); source->getRow(i, row_buffer); int pos = source.width(); if (add_tradable) { for (int k=0; k<asset_name.size(); ++k, ++pos) { real volume = row_buffer[volume_index[k]]; if (!is_missing(volume) && (int)volume>=min_volume_threshold) v[pos] = 1.0; else v[pos] = 0.0; } } if (add_last_day_of_month) v[pos++] = (last_day_of_month_index.contains(i)) ? 1.0 : 0.0; if (add_moving_average) { int price_pos = 0; for (int j=0; j<asset_name.length(); j++) { for (int k=0; k<prices_tag.size(); k++) { int index = price_index[price_pos++]; int prices_length = MIN(max_moving_average_window, i+1); int prices_start = i+1 - prices_length; Vec prices(prices_length); for (int l=0; l<prices_length; l++) prices[l] = source->get(l+prices_start,index); for (int l=0; l<moving_average_window.size(); l++) { int start = MAX(prices.length()-moving_average_window[l], 0); int len = prices.length() - start; v[pos++] = mean(prices.subVec(start,len),true); } } } } if (add_rollover_info) { for (int k=0; k<asset_name.size(); ++k, ++pos) { v[pos] = (rollover_date[k].find(i)==-1 ? 0.0 : 1.0); } } }
OptionList & PLearn::FinancePreprocVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file FinancePreprocVMatrix.cc.
OptionMap & PLearn::FinancePreprocVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file FinancePreprocVMatrix.cc.
RemoteMethodMap & PLearn::FinancePreprocVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file FinancePreprocVMatrix.cc.
void PLearn::FinancePreprocVMatrix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 347 of file FinancePreprocVMatrix.cc.
References asset_name, PLearn::deepCopyField(), expiration_index, PLearn::SourceVMatrix::makeDeepCopyFromShallowCopy(), moving_average_window, price_index, prices_tag, and volume_index.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(prices_tag, copies); deepCopyField(moving_average_window, copies); deepCopyField(asset_name, copies); deepCopyField(volume_index, copies); deepCopyField(price_index, copies); deepCopyField(price_index, copies); deepCopyField(expiration_index, copies); }
void PLearn::FinancePreprocVMatrix::setVMFields | ( | ) | [protected] |
Definition at line 205 of file FinancePreprocVMatrix.cc.
References add_last_day_of_month, add_moving_average, add_rollover_info, add_tradable, asset_name, PLearn::VMatrix::declareField(), PLearn::VMField::DiscrGeneral, i, j, moving_average_window, prices_tag, PLearn::TVec< T >::size(), PLearn::SourceVMatrix::source, PLearn::tostring(), and PLearn::VMat::width().
Referenced by build_().
{ Array<VMField>& orig_fields = source->getFieldInfos(); for (int i=0; i<orig_fields.size(); i++) declareField(i, orig_fields[i].name, orig_fields[i].fieldtype); int pos = source.width(); if (add_tradable) { for (int i=0; i<asset_name.size(); ++i) { string name = asset_name[i]+":is_tradable"; declareField(pos++, name, VMField::DiscrGeneral); } } if (add_last_day_of_month) declareField(pos++, "is_last_day_of_month", VMField::DiscrGeneral); if (add_moving_average) { for (int i=0; i<asset_name.size(); i++) { for (int j=0; j<prices_tag.size(); j++) { for (int k=0; k<moving_average_window.size(); k++) { string moving_average_name_col = asset_name[i]+":"+prices_tag[j]+":moving_average:w="+tostring(moving_average_window[k]); declareField(pos++, moving_average_name_col, VMField::DiscrGeneral); } } } } if (add_rollover_info) { for (int i=0; i<asset_name.size(); ++i) { string name = asset_name[i]+":rollover"; declareField(pos++, name, VMField::DiscrGeneral); } } }
Reimplemented from PLearn::SourceVMatrix.
Definition at line 168 of file FinancePreprocVMatrix.h.
do we include the information about the last tradable day of the month
Definition at line 62 of file FinancePreprocVMatrix.h.
Referenced by build_(), declareOptions(), getNewRow(), and setVMFields().
do we include the moving average statistics on the price_tag indexes
Definition at line 65 of file FinancePreprocVMatrix.h.
Referenced by build_(), declareOptions(), getNewRow(), and setVMFields().
add a column with '1' when the rollover occur (new expiration date)
Definition at line 68 of file FinancePreprocVMatrix.h.
Referenced by build_(), declareOptions(), getNewRow(), and setVMFields().
all the asset names
do we include the information telling if this day is tradable or not
Definition at line 59 of file FinancePreprocVMatrix.h.
Referenced by build_(), declareOptions(), getNewRow(), and setVMFields().
Definition at line 56 of file FinancePreprocVMatrix.h.
Referenced by build_(), getNewRow(), makeDeepCopyFromShallowCopy(), and setVMFields().
"volume" by default
"Date" by default. Only used if add_last_day_of_month==true
Definition at line 83 of file FinancePreprocVMatrix.h.
Referenced by build_(), and declareOptions().
TVec<int> PLearn::FinancePreprocVMatrix::expiration_index [protected] |
the index of the expiration-date (related to the expiration_tag)
Definition at line 104 of file FinancePreprocVMatrix.h.
Referenced by build_(), and makeDeepCopyFromShallowCopy().
"expiration-date" by default. Only used if add_rollover_info==true
Definition at line 86 of file FinancePreprocVMatrix.h.
Referenced by build_(), and declareOptions().
is the last day a last day of month? (default=false)
Definition at line 93 of file FinancePreprocVMatrix.h.
Referenced by build_().
0 by default (last day of month).
Set last_day=15 to simulate last_day_of_month as the 15 of each month
Definition at line 90 of file FinancePreprocVMatrix.h.
Referenced by build_(), and declareOptions().
the index of all the last tradable day of the month, base on the date column of the source matrix
Definition at line 108 of file FinancePreprocVMatrix.h.
Referenced by build_(), and getNewRow().
the maximum value of moving_average_window
Definition at line 111 of file FinancePreprocVMatrix.h.
Referenced by build_(), and getNewRow().
tradable = 1 if volume>min_volume_threshold
Definition at line 71 of file FinancePreprocVMatrix.h.
Referenced by declareOptions(), and getNewRow().
the window size of the moving average
Definition at line 78 of file FinancePreprocVMatrix.h.
Referenced by build_(), declareOptions(), getNewRow(), makeDeepCopyFromShallowCopy(), and setVMFields().
TVec<int> PLearn::FinancePreprocVMatrix::price_index [protected] |
the indexes of all the prices on which we want to compute some stats
Definition at line 101 of file FinancePreprocVMatrix.h.
Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().
all the price tags on which we want to compute the moving average (e.g.
close:level)
Definition at line 75 of file FinancePreprocVMatrix.h.
Referenced by build_(), declareOptions(), getNewRow(), makeDeepCopyFromShallowCopy(), and setVMFields().
TVec< TVec<int> > PLearn::FinancePreprocVMatrix::rollover_date [protected] |
Definition at line 113 of file FinancePreprocVMatrix.h.
Referenced by build_(), and getNewRow().
Vec PLearn::FinancePreprocVMatrix::row_buffer [protected] |
the position (date) of all rollover
Definition at line 114 of file FinancePreprocVMatrix.h.
Referenced by getNewRow().
TVec<int> PLearn::FinancePreprocVMatrix::volume_index [protected] |
the indexes (in the vmat) of all the volume columns
Definition at line 98 of file FinancePreprocVMatrix.h.
Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().
Definition at line 80 of file FinancePreprocVMatrix.h.
Referenced by build_(), and declareOptions().