Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
MSDM5058 Information Science
Computational Project II:
Teamwork in Portfolio Management Using
Prediction Rules and Communication in Social Networks
1
This computational project consists of twelve parts, of which the “extra” ones
are optional. You need to complete the project in groups of two to four people.
While you will analyze the same data and can share graphs with your group-
mates, you need to write an individual report, which will be appraised inde-
pendently from theirs. Your report must conform to the LNCS format, other-
wise 10% of score will be deducted from your report. You need to submit your
report onto Canvas at the latest on 14 May, 2022.
Data Preprocessing
Choose a stock available on more than 4000 days from any credible sources, e.g.
Yahoo Finance. Denote its closing-price time series as s(t), where “today” t = 0 is
defined so that the length ratio of the past {s(t) | t ≤ 0} to the future {s(t) ∣ t > 0} is
around 3:1.
• Compute its daily return
x(t) =
s(t) – s(t–1)
s(t–1)
. (1)
• Digitize x(t) as d(t) with three alphabets, viz. D for “down”, U for “up”, and H for
“hold”. You need to decide a sensible value for the positive constant ε.
d(t) = {
D [x(t) < – ε]
U [x(t) > + ε]
H (otherwise)
(2)
• Split all series at t = 0 into a learning set (t ≤ 0) and a testing set (t > 0). Work on
the learning sets until Section 5, then work on the testing sets from Section 6 on-
wards.
2 Cumulative Distribution Function
Given the return x(t) on one day, we would like to predict its value x(t+1) one day
later. However, a quantitative prediction is too ambitious; it is more realistic to predict
d(t+1) qualitatively instead. Let us focus on d(t+1) = U and d(t+1) = D, which respec-
tively correspond to a strong bullish and a strong bearish market.
2
• Plot the conditional CDFs FU(x) = CDF[x(t) ∣ d(t+1) = U] and FD(x) = CDF[x(t) ∣
d(t+1) = D].
3 Probability Density Function
We would then like to extract their corresponding PDFs, viz. PDF[x(t) ∣ d(t+1) = U]
and PDF[x(t) ∣ d(t+1) = D].
• Fit FU(x) and FD(x) with a Fermi-Dirac distribution
F(x) =
1
1+ exp[–b(x – x0)]
. (3)
Then plot the fitted distributions’ derivatives fU(x) and fD(x) on the same graph.
They estimate the desired PDFs.
• On the other hand, consider a Gaussian distribution (let us use this name instead of
a normal distribution to parallel a Fermi-Dirac distribution)
g(x) =
1
√2πσ2
exp [–
(x – μ)2
2σ2
] . (4)
Compute the means μ and the variances σ2 of {x(t) ∣ d(t+1) = U} and {x(t) ∣ d(t+1)
= D}, then fit the desired PDFs as gU(x) and gD(x). Plot them on the same graph.
4 Bayes Detector
We now construct a Bayes detector with the PDFs to predict d(t+1). Formally, we
choose between two hypotheses HU: d(t+1) = U and HD: d(t+1) = D after observing
x(t).
• Compute the probabilities P[d(t+1) = U] and P[d(t+1) = D]. These are the hypothe-
ses’ prior probabilities.
• Construct the detector with the Fermi-Dirac PDFs fU(x) and fD(x). In general, x
(x1, x2) favors one hypothesis, whereas x < x1 or x > x2 favors the other. Plot x = x1
and x = x2 on the graph of fU(x) and fD(x).
• Repeat last step with the Gaussian PDFs gU(x) and gD(x).
5 Association Rules
Prediction in U suggests buying stocks, whereas prediction in D suggests selling
stocks. In principle, we can simply follow the Bayes detectors and trade accordingly,
but we will end up trading too frequently and lose a lot due to transaction costs.
Therefore, we impose extra association rules to limit the frequency of trading. For X =
U or X = D, a k-day rule takes the general form of
3
RX
k : {d(t–k+1), d(t–k+2),…, d(t)} → d(t+1) = X . (5)
• Mine the two best 1-day rules RU
1 and RD
1 , then report their support and confidence.
You need to decide how to measure a rule’s goodness, e.g. with support, confi-
dence, lift, or other indicators. If you do not use support or confidence, report the
rules’ measured goodness as well.
• Repeat last step with the two best 5-day rules RU
5 and RD
5 .
6 Portfolio Management
Now, invest in the stock to see if the Bayes detectors and association rules really
work. Let M(t) be the amount of your money and N(t) the number of shares you own
at the end of the tth day. Your portfolio’s monetary value is measured with
V(t) = M(t) + N(t) s(t) . (6)
Initially, you are given M(0) = $100,000 and N(0) = 0 shares. Then you start trading
according to the following rules at t = 1.
─ When you observe the antecedent of RU
k on the tth day and your Bayes detector
predicts d(t+1) = U, buy stocks at the price s(t) and update
{
M(t) ← M(t) – m
N(t) ← N(t) + m/s(t)
for m = γM(t) . (7)
─ When you observe the antecedent of RD
k on the tth day and your Bayes detector
predicts d(t+1) = D, sell stocks at the price s(t) and update
{
M(t) ← M(t) + ns(t)
N(t) ← N(t) – n
for n = γN(t) . (8)
The constant parameter γ (0, 1) quantifies your “greed”. The greedier you are, the
more you want to earn and thus the more money or stock you trade per transaction.
Choose any value γ0 you like for the time being. Note that this market model has
made several unrealistic assumptions for simplicity.
1. The stock’s closing price s(t) becomes its price on the entire tth day.
2. The stock’s price is measured in dollars regardless of its original market.
3. M(t) and N(t) do not have any smallest unit per transaction, so they can be any real
numbers.
4. You trade at most once on one day.
First compare the performance of the two Bayes detectors obtained in Section 4. Con-
sider k = 1 and γ = γ0.
• Trade according to the Fermi-Dirac Bayes detector. Plot the portfolio’s monetary
value Vf (t).
4
• Trade again according to the Gaussian Bayes detector. Plot the portfolio’s mone-
tary value Vg(t).
• Which Bayes detector performs better? Stick to the better detector in the following
sections.
• Extra. Repeat the analysis with k = 5. Does it change the detectors’ performance?
7 Transaction Cost
A stock market usually charges certain execution fee upon transaction. Therefore, we
modify the scheme of buying and selling as Eq. (9) and (10) by including some tax ξ.
{
M(t) ← M(t) – m
N(t) ← N(t) + (1–ξ)m/s(t)
for m = γM(t) (9)
{
M(t) ← M(t) + (1–ξ)ns(t)
N(t) ← N(t) – n
for n = γN(t) (10)
Intuitively, the tax favors a lower frequency of trading. Consider ξ = 0.2% and γ = γ0.
• Trade according to the 1-day rules. Plot the portfolio’s monetary value V1(t). How
often do you trade on average?
• Trade again according to the 5-day rules. Plot the portfolio’s monetary value V5(t).
How often do you trade on average?
• Which pair of rules perform better? Does this match your expectation? Stick to the
better rules in the following sections.
• Extra. Repeat the analysis with ξ = 0.1% and ξ = 0.5%. How does the rules’ per-
formance depend on ξ?
8 Risk-Free Interest
In addition to transaction costs, further assume that M(t) grows without risk because it
is deposited in a bank or used to invest in a government bond. Anyhow, at the begin-
ning of each day, first update
M(t) ← M(t) (1+r) (11)
for some daily interest rate r. Consider ξ = 0.2%, r = 0.001%, and γ = γ0.
• Trade and plot the portfolio’s monetary value Vr(t).
• If you do not trade at all, your portfolio’s monetary value reduces to
Mr(t) = M(0) (1+r)t , (12)
which can serve as a portfolio’s benchmark value. Plot the ratio ρr(t) = Vr(t)/Mr(t).
• Extra. Repeat the analysis with r = 0.005% and r = 0.01%, whereas r = 0 in Sec-
tion 7. How does ρr(t) depend on r?
5
9 Greed
Now let us investigate the effect of γ. Consider ξ = 0.2% and r = 0.001%.
• Trade and plot the portfolio’s monetary value Vγ(t) for γ {0.1, 0.3, 0.5, 0.7, 0.9}.
• Plot the last monetary value Vγ(max t), the highest monetary value maxt Vγ(t), and
the average monetary value Vγ(t) against γ. Hence discuss the effect of γ.
• Extra. Repeat the analysis with fifteen more samples of γ.
10 Alternative Portfolio Measure
Instead of its monetary value, we may alternatively measure a portfolio’s worth W(t)
in terms of number of shares.
W(t) = N(t) + M(t) / s(t) (13)
Consider ξ = 0.2% and r = 0.001%.
• Trade with γ {0.1, 0.3, 0.5, 0.7, 0.9}, then compute each portfolio’s monetary
value Vγ(t) and worth Wγ(t).
• Plot v(t) = ln[Vγ(t)/V(0)] and w(t) = ln[Wγ(t)/W(0)]. Do they always have the same
sign?
• Plot vi = ln[Vγ(ti)/Vγ(ti–1)] and wi = ln[Wγ(ti)/Wγ(ti–1)] against i, where the ith trans-
action happens at t = ti. Do they always have the same sign?
• Extra. Note that v(tj) = i=1
j
vi and w(tj) = i=1
j
wi. Have you gained or lost when the
signs of v(t) and w(t) are different?
11 Efficient Frontier
While it seems a bit arbitrary to trade with m = γM(t) and n = γN(t) per transaction, we
may justify these amounts with the efficient frontier and hence generalize the scheme
of investment.
Denote the expected returns of the portfolio, M(t), and s(t) as {u, u1, u2} and their
risks as {σ2, σ1
2, σ2
2}. As M(t) is risk-free, σ1
2 = 0. The minimum-risk portfolio thus
consists of 100% of money and 0% of stock, whereas the maximum-risk portfolio
consists of 0% of money and 100% of stock. Consequently, u1 ≤ u ≤ u2: the more
money you hold, the less risky your portfolio is, but it gives a lower return.
Suppose we have observed the signal of buying on the tth day. Right before buy-
ing, u = Au1 + (1–A)u2, where A = M(t)/[M(t) + N(t)s(t)] is the proportion of money.