139const Int_t nrStocks = 10;
 
  140static const Char_t *stocks[] =
 
  141     {
"GE",
"SUNW",
"QCOM",
"BRCM",
"TYC",
"IBM",
"AMAT",
"C",
"PFE",
"HD"};
 
  154     fDate = fVol = fOpen = fHigh = fLow = fClose = fCloseAdj = 0;
 
  156  virtual ~TStockDaily() {}
 
  171  TStockDaily *
data = 0;
 
  179  for (
Int_t i = 0; i < nrEntries; i++) {
 
  182    if (
data->fDate >= sDay && 
data->fDate <= eDay)
 
  183      closeAdj[i] = 
data->fCloseAdj/100.;
 
  187  for (
Int_t i = 1; i < nrEntries; i++)
 
  189    (*
r)[i-1] = closeAdj[i]/closeAdj[i-1];
 
  214  const Int_t nrVar     = nrStocks;
 
  215  const Int_t nrEqual   = 1;
 
  216  const Int_t nrInEqual = 0;
 
  258  TQpDataDens *prob = (
TQpDataDens *)qp->
MakeData(
c,Q,xlo,ixlo,xup,ixup,A,
b,C,clo,iclo,cup,icup);
 
  270  const Int_t status = s->
Solve(prob,vars,resid);
 
  274  delete qp; 
delete prob; 
delete vars; 
delete resid; 
delete s;
 
  276    cout << 
"Could not solve this problem." <<endl;
 
  287   const Int_t sDay = 20000809;
 
  288   const Int_t eDay = 20040602;
 
  290   const char *fname = 
"stock.root";
 
  297      printf(
"accessing %s file from http://root.cern.ch/files\n",fname);
 
  303   for (
Int_t i = 0; i < nrStocks; i++) {
 
  304      const TString symbol = stocks[i];
 
  305      data[i] = StockReturn(
f,symbol,sDay,eDay);
 
  311   for (
Int_t i = 0; i < nrStocks; i++)
 
  312      r[i] = 
data[i].GetSum()/nrData;
 
  315   for (
Int_t i = 0; i < nrStocks; i++) {
 
  316      for (
Int_t j = 0; j <= i; j++) {
 
  318         for (
Int_t k = 0; k < nrData; k++) {
 
  321         Covar(i,j) = Covar(j,i) = 
sum/nrData;
 
  325   const TVectorD weight1 = OptimalInvest(2.0,
r,Covar);
 
  326   const TVectorD weight2 = OptimalInvest(10.,
r,Covar);
 
  328   cout << 
"stock     daily  daily   w1     w2" <<endl;
 
  329   cout << 
"symb      return sdv              " <<endl;
 
  330   for (
Int_t i = 0; i < nrStocks; i++)
 
  331      printf(
"%s\t: %.3f  %.3f  %.3f  %.3f\n",stocks[i],
r[i],
TMath::Sqrt(Covar[i][i]),weight1[i],weight2[i]);
 
  342   TF1 *
f1 = 
new TF1(
"f1",RiskProfile,0,2.5,1);
 
  350   TF1 *f2 = 
new TF1(
"f2",RiskProfile,0,2.5,1);
 
  357   legend1->
AddEntry(f2,
"1-exp(-10.*x)",
"l");
 
  363   TH1F *
h1 = 
new TH1F(
"h1",
"Portfolio Distribution",nrStocks,0,0);
 
  364   TH1F *h2 = 
new TH1F(
"h2",
"Portfolio Distribution",nrStocks,0,0);
 
  372   for (
Int_t i = 0; i < nrStocks; i++) {
 
  373      h1->
Fill(stocks[i],weight1[i]);
 
  374      h2->
Fill(stocks[i],weight2[i]);
 
  378   h2->
Draw(
"BAR2SAME HIST");
 
  382   legend2->
AddEntry(h2,
"low  risk",
"f");
 
#define ClassDef(name, id)
 
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
 
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
 
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
 
R__EXTERN TSystem * gSystem
 
TVectorT< Double_t > TVectorD
 
Array of floats (32 bits per element).
 
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
 
virtual void SetLineColor(Color_t lcolor)
Set the line color.
 
A TTree is a list of TBranches.
 
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all leaves of entry and return total number of bytes read.
 
virtual TH1 * GetHistogram() const
Return a pointer to the histogram used to visualise the function Note that this histogram is managed ...
 
void Draw(Option_t *option="") override
Draw this function with its current attributes.
 
virtual void SetParameter(Int_t param, Double_t value)
 
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
 
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
 
Derived class of TQpSolverBase implementing Gondzio-correction version of Mehrotra's original predict...
 
Int_t Solve(TQpDataBase *prob, TQpVar *iterate, TQpResidual *resid) override
Solve the quadratic programming problem as formulated through prob, store the final solution in itera...
 
1-D histogram with a float per channel (see TH1 documentation)}
 
virtual void SetBarOffset(Float_t offset=0.25)
Set the bar offset as fraction of the bin width for drawing mode "B".
 
virtual void SetXTitle(const char *title)
 
virtual void SetMaximum(Double_t maximum=-1111)
 
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
 
void Draw(Option_t *option="") override
Draw this histogram with options.
 
virtual void SetMinimum(Double_t minimum=-1111)
 
virtual void SetYTitle(const char *title)
 
virtual void SetBarWidth(Float_t width=0.5)
Set the width of bars as fraction of the bin width for drawing mode "B".
 
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
 
This class displays a legend box (TPaveText) containing several legend entries.
 
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
 
void Draw(Option_t *option="") override
Draw this legend with its current attributes.
 
Data for the dense QP formulation.
 
dense matrix problem formulation
 
TQpVar * MakeVariables(const TQpDataBase *data) override
Setup the variables.
 
virtual TQpDataBase * MakeData(Double_t *c, Double_t *Q, Double_t *xlo, Bool_t *ixlo, Double_t *xup, Bool_t *ixup, Double_t *A, Double_t *bA, Double_t *C, Double_t *clo, Bool_t *iclo, Double_t *cup, Bool_t *icup)
Setup the data.
 
TQpResidual * MakeResiduals(const TQpDataBase *data) override
Setup the residuals.
 
The Residuals class calculates and stores the quantities that appear on the right-hand side of the li...
 
Class containing the variables for the general QP formulation.
 
static const TString & GetTutorialDir()
Get the tutorials directory in the installation. Static utility function.
 
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
 
A TTree represents a columnar dataset.
 
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
 
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=nullptr)
Change branch address, dealing with clone trees properly.
 
virtual Long64_t GetEntries() const
 
constexpr Double_t C()
Velocity of light in .
 
Double_t Exp(Double_t x)
Returns the base-e exponential function of x, which is e raised to the power x.
 
Double_t Sqrt(Double_t x)
Returns the square root of x.
 
static uint64_t sum(uint64_t i)