lib/FuturesData.cpp

Go to the documentation of this file.
00001 /*
00002  *  Qtstalker stock charter
00003  *
00004  *  Copyright (C) 2001-2007 Stefan S. Stratigakos
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019  *  USA.
00020  */
00021 
00022 #include "FuturesData.h"
00023 #include <qobject.h>
00024 #include <qfileinfo.h>
00025 
00026 FuturesData::FuturesData ()
00027 {
00028   monthList.append("F");
00029   monthList.append("G");
00030   monthList.append("H");
00031   monthList.append("J");
00032   monthList.append("K");
00033   monthList.append("M");
00034   monthList.append("N");
00035   monthList.append("Q");
00036   monthList.append("U");
00037   monthList.append("V");
00038   monthList.append("X");
00039   monthList.append("Z");
00040 
00041   symbolList.append("AD");
00042   symbolList.append("BO");
00043   symbolList.append("NB");
00044   symbolList.append("BP");
00045   symbolList.append("C");
00046   symbolList.append("CC");
00047   symbolList.append("CO");
00048   symbolList.append("CD");
00049   symbolList.append("CL");
00050   symbolList.append("CR");
00051   symbolList.append("CT");
00052   symbolList.append("DJ");
00053   symbolList.append("DX");
00054   symbolList.append("EC");
00055   symbolList.append("ED");
00056   symbolList.append("ES");
00057   symbolList.append("FC");
00058   symbolList.append("GC");
00059   symbolList.append("GI");
00060   symbolList.append("HG");
00061   symbolList.append("HO");
00062   symbolList.append("HU");
00063   symbolList.append("OJ");
00064   symbolList.append("JO");
00065   symbolList.append("JY");
00066   symbolList.append("KC");
00067   symbolList.append("LB");
00068   symbolList.append("LC");
00069   symbolList.append("LN");
00070   symbolList.append("LH");
00071   symbolList.append("ND");
00072   symbolList.append("NG");
00073   symbolList.append("NQ");
00074   symbolList.append("O");
00075   symbolList.append("PA");
00076   symbolList.append("PB");
00077   symbolList.append("PL");
00078   symbolList.append("S");
00079   symbolList.append("SB");
00080   symbolList.append("SF");
00081   symbolList.append("SI");
00082   symbolList.append("SM");
00083   symbolList.append("SP");
00084   symbolList.append("TY");
00085   symbolList.append("TYD");
00086   symbolList.append("US");
00087   symbolList.append("USD");
00088   symbolList.append("W");
00089   symbolList.append("YX");
00090   symbolList.append("FW20");
00091 
00092   cme = "CME";
00093   cbot = "CBOT";
00094   nymex = "NYMEX";
00095   nybot = "NYBOT";
00096   hmuz = "H,M,U,Z";
00097   hknuz = "H,K,N,U,Z";
00098   all = "F,G,H,J,K,M,N,Q,U,V,X,Z";
00099 }
00100 
00101 FuturesData::~FuturesData ()
00102 {
00103 }
00104 
00105 void FuturesData::getName (QString &d)
00106 {
00107   d = name;
00108 }
00109 
00110 void FuturesData::getSymbol (QString &d)
00111 {
00112   d = symbol;
00113 }
00114 
00115 void FuturesData::getExchange (QString &d)
00116 {
00117   d = exchange;
00118 }
00119 
00120 void FuturesData::getContract (QString &d)
00121 {
00122   d = contract;
00123 }
00124 
00125 double FuturesData::getLimit ()
00126 {
00127   return limit;
00128 }
00129 
00130 double FuturesData::getRate ()
00131 {
00132   return rate;
00133 }
00134 
00135 void FuturesData::getSymbolList (QStringList &l)
00136 {
00137   l = symbolList;
00138 }
00139 
00140 void FuturesData::getCMESymbolList (QStringList &l)
00141 {
00142   l.clear();
00143   l.append("AD");
00144   l.append("NB");
00145   l.append("CD");
00146   l.append("EC");
00147   l.append("ED");
00148   l.append("ES");
00149   l.append("FC");
00150   l.append("GI");
00151   l.append("JY");
00152   l.append("LB");
00153   l.append("LC");
00154   l.append("LN");
00155   l.append("ND");
00156   l.append("NQ");
00157   l.append("PB");
00158   l.append("SF");
00159   l.append("SP");
00160 }
00161 
00162 void FuturesData::getMonthList (QStringList &l)
00163 {
00164   l.clear();
00165   l = QStringList::split(",", month, FALSE);
00166 }
00167 
00168 void FuturesData::getMonths (QStringList &l)
00169 {
00170   l = monthList;
00171 }
00172 
00173 int FuturesData::setSymbol (QString &d)
00174 {
00175   name.truncate(0);
00176   month.truncate(0);
00177   exchange.truncate(0);
00178   symbol.truncate(0);
00179   rate = 0;
00180   limit = 0;
00181 
00182   bool rc = TRUE;
00183   int i = symbolList.findIndex(d);
00184   switch (i)
00185   {
00186     case AD:  
00187       name = QObject::tr("Australian Dollar");
00188       rate = 1000;
00189       month = hmuz;
00190       exchange = cme;
00191       symbol = "AD";
00192       rc = FALSE;
00193       break;
00194     case BO:
00195       name = QObject::tr("Soybean Oil");
00196       rate = 600;
00197       month = "F,H,K,N,Q,U,V,Z";
00198       limit = 2;
00199       exchange = cbot;
00200       symbol = "BO";
00201       rc = FALSE;
00202       break;
00203     case BP:
00204     case NB:  
00205       name = QObject::tr("British Pound");
00206       rate = 625;
00207       month = hmuz;
00208       exchange = cme;
00209       symbol = "NB";
00210       rc = FALSE;
00211       break;
00212     case C:
00213       name = QObject::tr("Corn");
00214       rate = 50;
00215       month = hknuz;
00216       limit = 20;
00217       exchange = cbot;
00218       symbol = "C";
00219       rc = FALSE;
00220       break;
00221     case CC:
00222     case CO:
00223       name = QObject::tr("Cocoa");
00224       rate = 10;
00225       month = hknuz;
00226       exchange = nybot;
00227       symbol = "CC";
00228       rc = FALSE;
00229       break;
00230     case CD:
00231       name = QObject::tr("Canadian Dollar");
00232       rate = 1000;
00233       month = hmuz;
00234       exchange = cme;
00235       symbol = "CD";
00236       rc = FALSE;
00237       break;
00238     case CL:
00239       name = QObject::tr("Crude Oil");
00240       rate = 1000;
00241       month = all;
00242       limit = 3;
00243       exchange = nymex;
00244       symbol = "CL";
00245       rc = FALSE;
00246       break;
00247     case CR:
00248       name = QObject::tr("CRB Index");
00249       month = "F,G,J,M,Q,X";
00250       exchange = nybot;
00251       symbol = "CR";
00252       rc = FALSE;
00253       break;
00254     case CT:
00255       name = QObject::tr("Cotton");
00256       rate = 500;
00257       month = "H,K,N,V,Z";
00258       limit = 3;
00259       exchange = nybot;
00260       symbol = "CT";
00261       rc = FALSE;
00262       break;
00263     case DJ:
00264       name = QObject::tr("Dow Jones Industrial Average");
00265       month = hmuz;
00266       exchange = cbot;
00267       symbol = "DJ";
00268       rc = FALSE;
00269       break;
00270     case DX:
00271       name = QObject::tr("US Dollar Index");
00272       rate = 1000;
00273       month = hmuz;
00274       exchange = nybot;
00275       symbol = "DX";
00276       rc = FALSE;
00277       break;
00278     case EC:
00279       name = QObject::tr("Euro");
00280       month = hmuz;
00281       exchange = cme;
00282       symbol = "EC";
00283       rc = FALSE;
00284       break;
00285     case ED:
00286       name = QObject::tr("Eurodollar");
00287       rate = 2500;
00288       month = hmuz;
00289       exchange = cme;
00290       symbol = "ED";
00291       rc = FALSE;
00292       break;
00293     case ES:
00294       name = QObject::tr("E-MINI S&P 500");
00295       month = hmuz;
00296       exchange = cme;
00297       rate = 50;
00298       symbol = "ES";
00299       rc = FALSE;
00300       break;
00301     case FC:
00302       name = QObject::tr("Feeder Cattle");
00303       rate = 500;
00304       month = "F,H,J,K,Q,U,V,X";
00305       limit = 1.5;
00306       exchange = cme;
00307       symbol = "FC";
00308       rc = FALSE;
00309       break;
00310     case GC:
00311       name = QObject::tr("Gold");
00312       rate = 100;
00313       month = "G,J,M,Q,V,Z";
00314       limit = 75;
00315       symbol = "GC";
00316       exchange = nymex;
00317       rc = FALSE;
00318       break;
00319     case GI:
00320       name = QObject::tr("Goldman Sachs Commodity Index");
00321       month = all;
00322       symbol = "GI";
00323       exchange = cme;
00324       rc = FALSE;
00325       break;
00326     case HG:
00327       name = QObject::tr("Copper");
00328       rate = 250;
00329       month = hknuz;
00330       limit = 20;
00331       symbol = "HG";
00332       exchange = nymex;
00333       rc = FALSE;
00334       break;
00335     case HO:
00336       name = QObject::tr("Heating Oil");
00337       rate = 40000;
00338       month = all;
00339       limit = 6;
00340       symbol = "HO";
00341       exchange = nymex;
00342       rc = FALSE;
00343       break;
00344     case HU:
00345       name = QObject::tr("Unleaded Gasoline");
00346       rate = 40000;
00347       month = all;
00348       limit = 6;
00349       symbol = "HU";
00350       exchange = nymex;
00351       rc = FALSE;
00352       break;
00353     case OJ:
00354     case JO:
00355       name = QObject::tr("Frozen Concentrated Orange Juice");
00356       rate = 150;
00357       month = "F,H,K,N,U,X";
00358       limit = 5;
00359       symbol = "OJ";
00360       exchange = nybot;
00361       rc = FALSE;
00362       break;
00363     case JY:
00364       symbol = QObject::tr("Japanese Yen");
00365       rate = 1250;
00366       month = hmuz;
00367       symbol = "JY";
00368       exchange = cme;
00369       rc = FALSE;
00370       break;
00371     case KC:
00372       name = QObject::tr("Coffee");
00373       rate = 375;
00374       month = hknuz;
00375       symbol = "KC";
00376       exchange = nybot;
00377       rc = FALSE;
00378       break;
00379     case LB:
00380       name = QObject::tr("Lumber");
00381       rate = 80;
00382       month = "F,H,K,N,U,X";
00383       limit = 10;
00384       exchange = cme;
00385       symbol = "LB";
00386       rc = FALSE;
00387       break;
00388     case LC:
00389       name = QObject::tr("Live Cattle");
00390       rate = 400;
00391       month = "G,J,M,Q,V,Z";
00392       limit = 1.5;
00393       exchange = cme;
00394       symbol = "LC";
00395       rc = FALSE;
00396       break;
00397     case LH:
00398     case LN:
00399       name = QObject::tr("Lean Hogs");
00400       rate = 400;
00401       month = "G,J,M,N,Q,V,Z";
00402       limit = 2;
00403       symbol = "LN";
00404       exchange = cme;
00405       rc = FALSE;
00406       break;
00407     case ND:
00408       name = QObject::tr("NASDAQ 100");
00409       month = hmuz;
00410       symbol = "ND";
00411       exchange = cme;
00412       rc = FALSE;
00413       break;
00414     case NG:
00415       name = QObject::tr("Natural Gas");
00416       rate = 10000;
00417       month = all;
00418       limit = 1;
00419       symbol = "NG";
00420       exchange = nymex;
00421       rc = FALSE;
00422       break;
00423     case NQ:
00424       name = QObject::tr("E-MINI NASDAQ 100");
00425       month = hmuz;
00426       symbol = "NQ";
00427       exchange = cme;
00428       rc = FALSE;
00429       break;
00430     case O:
00431       name = QObject::tr("Oats");
00432       rate = 50;
00433       month = hknuz;
00434       limit = 20;
00435       symbol = "O";
00436       exchange = cbot;
00437       rc = FALSE;
00438       break;
00439     case PA:
00440       name = QObject::tr("Palladium");
00441       rate = 100;
00442       month = hmuz;
00443       symbol = "PA";
00444       exchange = nymex;
00445       rc = FALSE;
00446       break;
00447     case PB:
00448       name = QObject::tr("Frozen Pork Bellies");
00449       rate = 400;
00450       month = "G,H,K,N,Q";
00451       limit = 3;
00452       symbol = "PB";
00453       exchange = cme;
00454       rc = FALSE;
00455       break;
00456     case PL:
00457       name = QObject::tr("Platinum");
00458       rate = 50;
00459       month = "F,J,N,V";
00460       limit = 50;
00461       symbol = "PL";
00462       exchange = nymex;
00463       rc = FALSE;
00464       break;
00465     case S:
00466       name = QObject::tr("Soybeans");
00467       rate = 50;
00468       limit = 50;
00469       month = "F,H,K,N,Q,U,X";
00470       symbol = "S";
00471       exchange = cbot;
00472       rc = FALSE;
00473       break;
00474     case SB:
00475       name = QObject::tr("Sugar #11 World");
00476       rate = 1120;
00477       month = "H,K,N,V";
00478       symbol = "SB";
00479       exchange = nybot;
00480       rc = FALSE;
00481       break;
00482     case SF:
00483       name = QObject::tr("Swiss Franc");
00484       rate = 1250;
00485       month = hmuz;
00486       symbol = "SF";
00487       exchange = cme;
00488       rc = FALSE;
00489       break;
00490     case SI:
00491       name = QObject::tr("Silver");
00492       rate = 100;
00493       month = "F,H,K,N,U,Z";
00494       rate = 150;
00495       symbol = "SI";
00496       exchange = nymex;
00497       rc = FALSE;
00498       break;
00499     case SM:
00500       name = QObject::tr("Soy Meal");
00501       rate = 100;
00502       month = "F,H,K,N,Q,U,V,Z";
00503       limit = 20;
00504       symbol = "SM";
00505       exchange = cbot;
00506       rc = FALSE;
00507       break;
00508     case SP:
00509       name = QObject::tr("S&P 500");
00510       month = hmuz;
00511       exchange = cme;
00512       rate = 250;
00513       symbol = "SP";
00514       rc = FALSE;
00515       break;
00516     case TY:
00517     case TYD:
00518       name = QObject::tr("Treasury Note 10 yr.");
00519       rate = 1000;
00520       month = hmuz;
00521       symbol = "TY";
00522       exchange = cbot;
00523       rc = FALSE;
00524       break;
00525     case US:
00526     case USD:
00527       name = QObject::tr("US Treasury Bond");
00528       rate = 1000;
00529       month = hmuz;
00530       symbol = "US";
00531       exchange = cbot;
00532       rc = FALSE;
00533       break;
00534     case W:
00535       name = QObject::tr("Wheat");
00536       rate = 50;
00537       month = hknuz;
00538       limit = 30;
00539       symbol = "W";
00540       exchange = cbot;
00541       rc = FALSE;
00542       break;
00543     case YX:
00544       name = QObject::tr("NYSE");
00545       month = hmuz;
00546       symbol = "YX";
00547       exchange = nybot;
00548       rc = FALSE;
00549       break;
00550     case FW20:
00551       // Warsaw Stock Exchange futures
00552       name = QObject::tr("WIG20 Index");
00553       month = hmuz;
00554       exchange = "WSE";
00555       rate = 10;
00556       symbol = "FW20";
00557       rc = FALSE;
00558       break;
00559     default:
00560       break;
00561   }
00562 
00563   if (rc)
00564     return rc;
00565     
00566   QDateTime dt = QDateTime::currentDateTime();
00567   getCurrentContract(dt, contract);
00568   
00569   return rc;
00570 }
00571 
00572 void FuturesData::getCurrentContract (QDateTime &dt, QString &cont)
00573 {
00574   cont = symbol;
00575   bool yearFlag = FALSE;
00576   QStringList ml;
00577   getMonthList(ml);
00578   QStringList fml;
00579   getMonths(fml);
00580 
00581   int currentMonth = dt.date().month() - 1;
00582 
00583   int i = ml.findIndex(fml[currentMonth]);
00584   if (i != -1)
00585   {
00586     currentMonth++;
00587     if (currentMonth == 12)
00588     {
00589       yearFlag = TRUE;
00590       currentMonth = 0;
00591     }
00592   }
00593 
00594   if (! symbol.compare("CL") ||
00595       ! symbol.compare("HO") ||
00596       ! symbol.compare("HU") ||
00597       ! symbol.compare("NG"))
00598   {
00599     currentMonth++;
00600     if (currentMonth == 12)
00601     {
00602       yearFlag = TRUE;
00603       currentMonth = 0;
00604     }
00605   }
00606 
00607   while (1)
00608   {
00609     QString s = fml[currentMonth];
00610     int i = ml.findIndex(s);
00611     if (i != -1)
00612     {
00613       if (yearFlag)
00614         cont.append(QString::number(dt.date().year() + 1));
00615       else
00616         cont.append(QString::number(dt.date().year()));
00617 
00618       cont.append(fml[currentMonth]);
00619       break;
00620     }
00621     else
00622     {
00623       currentMonth++;
00624       if (currentMonth == 12)
00625       {
00626         yearFlag = TRUE;
00627         currentMonth = 0;
00628       }
00629     }
00630   }
00631 }
00632 
00633 int FuturesData::setSymbolPath (QString &d)
00634 {
00635   QFileInfo fi(d);
00636   QString s = fi.fileName();
00637   if (s.length() == 7)
00638     s = s.left(2);
00639   else
00640     s = s.left(1);
00641   return setSymbol(s);
00642 }
00643