0% found this document useful (0 votes)
3 views18 pages

CS Technical Analysis

This case study presents a technical analysis application for stock market timing, focusing on determining optimal buy (X) and sell (Y) values to maximize profits over specified time horizons. It outlines two options: Option A, which analyzes fixed time horizons with varying X and Y values, and Option B, which adjusts the time horizon to find the best X and Y for different trading scenarios. The application includes user interfaces for input, options selection, and output display, along with detailed procedures for calculating profits based on historical market data.

Uploaded by

adonafek19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views18 pages

CS Technical Analysis

This case study presents a technical analysis application for stock market timing, focusing on determining optimal buy (X) and sell (Y) values to maximize profits over specified time horizons. It outlines two options: Option A, which analyzes fixed time horizons with varying X and Y values, and Option B, which adjusts the time horizon to find the best X and Y for different trading scenarios. The application includes user interfaces for input, options selection, and output display, along with detailed procedures for calculating profits based on historical market data.

Uploaded by

adonafek19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

CASE STUDY

seventeen
Technical Analysis

case study
OVERVIEW

CS17.1 Application Overview and Model Development


CS17.2 Worksheets
CS17.3 User Interface
CS17.4 Procedures
CS17.5 Re-solve Options
CS17.6 Summary
CS17.7 Extensions
CASE STUDY 17 Technical Analysis 2

CS17.1 Application Overview and Model Development


We assume that a person buys shares of a stock when the average market value for a
past time horizon falls below a certain value X; likewise, we assume that a person sells
shares of a stock when the average market value for a past time horizon rises above a
certain value Y. The “Technical Analysis of Market Timing” problem seeks to determine
values for X and Y and a maximum profit for buying and selling shares for a certain time
horizon. This application analyzes “Technical Analysis of Market Timing” for the two
following options:

Option A: The time horizon and a risk rate are set, and we then use various values of X
and Y (within a given bounds) to calculate the overall profit. A maximum profit is found
among these values.

Option B: The time horizon shifts (within a given bound) and the best values of X and Y
are determined for the maximum profit possible for scenarios of buy and sell, buy only,
and sell only.

CS19.1.1 Model Definition and Assumptions

Let’s now discuss how to make the calculations for determining the overall profit for a
given X and Y value. We perform these calculations in a calculation sheet with several
columns. Note that the formulas for these calculations are only in the rows corresponding
to the time horizon. In a later section, we will further describe the calculation sheet as well
as the procedure that generates the calculations, UpdateCalc.

The first two columns contain historical data from the S&P records, which we use to
calculate the average market price depending on X and Y. The next two columns check if
the investor can buy or sell shares based on the current trial value for X and Y,
respectively. We simply calculate the average market price based on the value of X for
buying and X for selling. We then enter the formulas and copy them for the time horizon
period.

Range("BuyCheck").Offset(StartCount, 0).FormulaR1C1 = "=AVERAGE(R[-" &


BuyX & "]C[-1]: R[-1]C[-1])"
Range("SellCheck").Offset(StartCount, 0).FormulaR1C1 = "=AVERAGE(R[-" &
SellY & "]C[-2]: R[-1]C[-2])"
Range(Range("BuyCheck").Offset(StartCount, 0),
Range("SellCheck").Offset(StartCount, 0)).Copy
Range(Range("BuyCheck").Offset(StartCount + 1, 0),
Range("SellCheck").Offset(EndCount, 0)).PasteSpecial

The next column checks whether or not the user currently owns shares. This is a logical
check to ensure that the user does not sell shares that he or she does not own. For the
first period in the time horizon, we perform this check using the initial number of shares
provided by the user in an input form. For the remaining periods, we check the number of
shares owned in the previous period.

If Range("StartShares").Value <> "" Then


Range("Own").Offset(StartCount, 0).Value = "Yes"
CASE STUDY 17 Technical Analysis 3

Else
Range("Own").Offset(StartCount, 0).Value = "No"
End If
Range("Own").Offset(StartCount + 1, 0).FormulaR1C1 = "=IF(R[-1]C[2] = ""Yes"",
""Yes"", IF(R[-1]C[3]=""Yes"", ""No"", R[-1]C))"
Range("Own").Offset(StartCount + 1, 0).Copy
Range(Range("Own").Offset(StartCount + 2, 0), Range("Own").Offset(EndCount,
0)).PasteSpecial

The next two columns confirm whether or not the user is going to buy or sell shares for the
current period. We check whether or not we are in a scenario in which we are buying or
selling. We then check whether or not the buy or sell check was met and whether or not
we have shares to sell.

Range("Buy").Offset(StartCount, 0).FormulaR1C1 =
"=IF(BuyAllowed=""Yes"",IF(AND(RC[-2] = ""No"", RC[-6]>RC[-5]),
""Yes"", ""No""),""No"")"
Range("Sell").Offset(StartCount, 0).FormulaR1C1 =
"=IF(SellAllowed=""Yes"",IF(AND(RC[-3] = ""Yes"", RC[-7]<RC[-5]),
""Yes"", ""No""),""No"")"
Range(Range("Buy").Offset(StartCount, 0), Range("Sell").Offset(StartCount,
0)).Copy
Range(Range("Buy").Offset(StartCount + 1, 0), Range("Sell").Offset(EndCount,
0)).PasteSpecial

For either action, we must determine the number of shares by assuming that we will either
buy all the shares for which we have funds or sell all the shares that we currently own.
When buying shares, we divide our current capital by the sum of the market price and the
transaction cost for buying.

Range("NumShares").Offset(StartCount, 0).FormulaR1C1 = "=IF(RC[-2]=""Yes"",


StartCap/(RC[-8]+CostBuy), " & "IF(RC[-1] = ""Yes"", 0, StartShares))"
Range("NumShares").Offset(StartCount + 1, 0).FormulaR1C1 = "=IF(RC[-2] =
""Yes"", R[-1]C[2]/(RC[-8]+CostBuy), " & "IF(RC[-1] = ""Yes"", 0, R[-1]C))"
Range("NumShares").Offset(StartCount + 1, 0).Copy
Range(Range("NumShares").Offset(StartCount+2,0),
Range("NumShares").Offset(EndCount, 0)).PasteSpecial

The next column calculates the cash flow. We begin with a starting capital specified by the
user in an input form. Any time we buy, we spend all of our money. This cost comes from
the market price of the stock and the transaction cost for buying shares. Any time we sell,
we sell all of our shares and therefore gain their market price in value. However, we also
incur a transaction cost for selling.

Range("CashFlow").Offset(StartCount, 0).FormulaR1C1 = "=IF(RC[-4] = ""Yes"",


StartCap-(RC[-10]+CostBuy)*RC[-2], " & "IF(RC[-3]=""Yes"",
StartCap+(RC[-10]-CostSell)*StartShares, StartCap+StartShares*Rate))"
Range("CashFlow").Offset(StartCount + 1, 0).FormulaR1C1 = "=IF(RC[-4] =
""Yes"", R[-1]C-(RC[-10]+CostBuy)*RC[-2] , " & "IF(RC[-3]=""Yes"", R[-
1]C+(RC[-10]-CostSell)*R[-1]C[-2], R[-1]C+RC[-2]*Rate))"
Range("CashFlow").Offset(StartCount + 1, 0).Copy
Range(Range("CashFlow").Offset(StartCount+2,0),
CASE STUDY 17 Technical Analysis 4

Range("CashFlow").Offset(EndCount, 0)).PasteSpecial

The overall profit is stored at the top of the sheet. It is equal to our cash flow at the end of
the time horizon.

Range("Profit").Formula = "=" & Range("CashFlow").Offset(EndCount,


0).Address

The formulas provided here are in terms of the cells and variables used in the sheet and
the procedure descriptions below.

CS19.1.2 Input

For both options, we require the following general input:


ƒ Initial capital
ƒ Initial number of shares
ƒ Risk free rate
ƒ Transaction costs for buying and selling shares
ƒ Upper and lower bounds on X and Y

For Option A, we require the following additional input:


ƒ Time horizon

For Option B, we require the following additional input:


ƒ Shift in time horizon:
ƒ Starting time
ƒ Ending time
ƒ Step size for start time
ƒ Interval size of time horizon trial values

CS19.1.3 Output

The output for Option A is:


ƒ Table with various X and Y values and profit values for each combination
ƒ Maximum profit and X and Y for maximum profit
ƒ Number of buys and sells at maximum profit

The output for Option B is:


ƒ X and Y that yield maximum profit for each scenario:
ƒ Buying and selling
ƒ Buying only
ƒ Selling only
Values for each scenario for various time horizons

CS17.2 Worksheets
We will use four worksheets in this application: the welcome sheet, a calculation sheet, an
output sheet for Option A, and an output sheet for Option B. The welcome sheet contains
the title and the description of the application as well as some images (see Figure
CS17.1). The “Start” button takes the user to an input form and then an options form. If the
CASE STUDY 17 Technical Analysis 5

user selects Option A, he or she will see the output sheet for Option A; otherwise, the
output sheet for Option B appears.

Figure CS17.1 The Welcome Sheet.

We determine the output for Option A and Option B by performing calculations on the
“Calculations” sheet (see Figure CS17.2), which the user can view by clicking a “View
Calc” button on either of the output sheets. The user can return to the output sheet by
clicking the “Back” button. An “End” button allows the user to exit the application.

Figure CS17.2(a)
CASE STUDY 17 Technical Analysis 6

Figure CS17.2(b)

Figure CS17.2 The Calculation sheet.

The first two columns contain historical data from the S&P records. The dates are
recorded by year and months, with months represented as decimals. The price per share
is included for each date. The next two columns check if the investor can buy or sell
shares based on the current trial value for X and Y, respectively. The next column checks
whether or not the user currently owns shares. As previously mentioned, this is a logical
check to ensure that the user does not sell shares he or she does not own.

Above the next set of columns are several input cells, which the user provided in the initial
input form and in the re-solve options on the output sheets. The “Buy Allowed” and “Sell
Allowed” cells permit the user to vary the scenarios for Option B. The “Buy” and “Sell”
columns confirm whether or not the user wants to buy or sell shares for the current period.
For either action, the number of shares is also determined. Next, we calculate the cash
flow in the next column and store the overall profit at the top of the sheet. Note that the
formulas for these calculations are only in the rows corresponding to the time horizon.

The output sheet for Option A has a worksheet user interface that allows the user to
specify the risk rate and the time horizon (see Figure CS17.3). Bounds for the X and Y
values have been set in the input form already. Based on these bounds, a table is created
to try different combinations of X and Y in the calculations. We record the overall profit for
each trial, the maximum profit amongst these is highlighted, and the number of buys and
sells at this maximum profit value.

If the user changes the risk rate or time horizon, he or she must then click the “Re-solve”
button to re-run the calculations. The “View Calc” button allows the user to view the
calculation sheet and the “End” button to exit the application.

The output sheet for Option B displays the X and Y values that yield a maximum profit for
a shifting time horizon (see Figure CS17.4). These X, Y, and profit values are calculated
for three different scenarios: buying and selling, buying only, and selling only. The time
horizon shifts according to the values provided by the user in a user form for Option B. If
the user wishes to changes these values, he or she can press the “Re-solve” button. The
“View Calc” button allows the user to view the calculation sheet and the “End” button to
exit the application.
CASE STUDY 17 Technical Analysis 7

Figure CS17.3 The output sheet for Option A.

Figure CS17.4 The output sheet for Option B.

Welcome sheet Application description and “Start” button.


Calculation sheet Input recorded and calculations performed.
Output sheet for Option
Summary Output for Option A recorded and re-solve options given.
A
Output sheet for Option
Output for Option B recorded and re-solve options given.
B
CASE STUDY 17 Technical Analysis 8

CS17.3 User Interface


This application consists of four user forms, some controls on the output for Option A
worksheet, and several navigational and functional buttons. The first form that the user
sees is the input form (see Figure CS17.5). This form records the initial capital, the initial
number of shares, the risk free rate, the transaction costs for buying and selling shares,
and the bounds for X and Y. If the user is solving Option A, he or she will have a chance
to modify the risk free rate and then re-solve. We use frames and text boxes to receive the
input, as well as some extra labels to clarify formatting to the user.

Figure CS17.5 The input form.

The next form that the user sees is the options form (see Figure CS17.6), which allows the
user to choose between Option A and Option B. We employ a frame with two mutually
exclusive option buttons.

Figure CS17.6 The options form.


CASE STUDY 17 Technical Analysis 9

If the user selects Option A, then the Option A form appears (see Figure CS17.7). This
form receives the initial values for the time horizon, which (along with the risk rate
provided in the input form) will be used to perform the initial calculations for Option A.

Figure CS17.7 The Option A initial time horizon form.

To re-solve Option A, the user does not return to any of these forms, but rather
manipulates the controls on the worksheet to change the risk rate and/or the time horizon
(see Figure CS17.8). We employ a spin button linked to a cell to allow the user to change
the risk rate. We include two text boxes and two combo boxes to allow the user to select
new years and/or months for the time horizon.

Figure CS17.8 The user interface controls on the output sheet for Option A.

If the user selects Option B from the option form, the Option B form appears next (see
Figure CS17.9). This form receives input for the shifting time horizon. The length of each
CASE STUDY 17 Technical Analysis 10

trial horizon is set in the “Period of Time per Interval” text box. The step size for the shift in
the starting date is also an input. The starting and ending dates are considered to be
bounds for the trial time horizons. We include combo boxes for the months of the time
horizon bounds. This form appears to the user again when he or she re-solves Option B.

Figure CS17.9 The Option B time horizon shift form.

Input Form Receives the initial input from the user.


Options Form Allows the user to select Option A or Option B.

Summary Option A Form Receives the initial time horizon for Option A.

Controls on output Allows the user to change the risk rate and the time horizon for
sheet for Option A resolving Option A.
Receives input for the shifting time horizon for Option B. Also
Option B Form
used in re-solve options for Option B.

CS17.4 Procedures
We will now outline the procedures for this application. We begin with the Main sub
procedure and variable definitions (see Figure CS17.10). The Main sub procedure simply
calls a ClearPrev procedure and displays the input form and options form. The ClearPrev
procedure clears the output sheets’ values and formatting for Option A and Option B. It
also initializes some variables.

The code to receive the input on the input form appears in Figure CS17.11. In this code,
the upper and lower bounds for X and Y are assigned to their corresponding variables.
The other input values are recorded on the calculations sheet. The application makes note
of the initial risk rate on the corresponding user interface of Option A’s output sheet.
CASE STUDY 17 Technical Analysis 11

Figure CS17.10 Variable declarations, Main procedure, and ClearPrev procedure.

Figure CS17.11 The code for the input form.

The code to receive the user’s selection on the options form appears in Figure CS17.12. If
the user selects Option A, then the output sheet for Option A is formatted, a corresponding
Boolean variable is set, the user is taken to the output sheet for Option A, and the Option
CASE STUDY 17 Technical Analysis 12

A form comes into view. Once the user has entered the initial time horizon in the Option A
form, the application calls the SolveA procedure. If the user selects Option B, a
corresponding Boolean variable is set, the user is taken to the output sheet for Option B,
and the application calls the SolveB procedure. In response to the SolveB procedure, the
Option B form appears to receive the time horizon shift input.

Figure CS17.12 The code for the options form.

The code for the Option A form records the initial time horizon on the user interface of
Option A’s output sheet (see Figure CS17.13). This form is also initialized to reveal the
first month to be selected in the “Month” combo boxes.

The SolveA procedure performs the main calculations for Option A (see Figure CS17.14).
It begins by determining whether or not we are solving Option A. If we are, then we record
any changes made to the user interface controls on the output sheet for Option A. We use
the SolveA procedure to solve Option B and should not record this information in that
case.

We then loop through all of the X,Y combinations to calculate their profit values and
determine the maximum profit scenario. To perform the calculations, we use an
UpdateCalc procedure (see Figure CS17.15), which loops through the rows in the
calculation sheet that correspond to the time horizon specified by the user. In these rows,
we enter all of the necessary formulas for each column in the calculation sheet.
CASE STUDY 17 Technical Analysis 13

Figure CS17.13 The code for the Option A form.

For Option B, we use the SolveB procedure shown in Figure CS17.16. This procedure
begins by displaying the Option B form to the user. Since we will display this form every
time Option B is re-solved, we call from the SolveB procedure instead of the options form.

Next, we loop through the various time horizon values, solving for the best X and Y values
for maximum profit each time. For each time horizon value, we examine three scenarios:
buying and selling, only buying, and only selling. To enforce these scenarios, we modify
the “Buy Allowed” and “Sell Allowed” cells on the calculation sheet. We call the SolveA
procedure to find the optimal X, Y, and profit values for each scenario. Again, the SolveA
procedure calls the UpdateCalc procedure to modify the calculation sheet formulas as
needed for the varying X, Y, and time horizon values.

The Option B form code simply records the time horizon bounds, step size, and interval
length (see Figure CS17.17). The form is also initialized to select the first month in the
“Months” combo boxes.
CASE STUDY 17 Technical Analysis 14

Figure CS17.14 The SolveA procedure.


CASE STUDY 17 Technical Analysis 15

Figure CS17.15 The UpdateCalc procedure.


CASE STUDY 17 Technical Analysis 16

Figure CS17.16 The SolveB procedure.

Figure CS17.17 The code for the Option B form.


CASE STUDY 17 Technical Analysis 17

We use the navigational procedures for the “End,” “View Calc,” and “Back” buttons (see
Figure CS17.18).

Figure CS17.18 Navigational procedures.

Main Initializes the application and retrieves the initial input from user.
Initializes the variables, clears previous values, and clears
ClearPrev
animation layout formatting.
Summary Input Form code Records the initial input.
Options Form code Determines whether to solve Option A or Option B.
Option A Form code Records initial time horizon for Option A.
Loops through combinations of X and Y to determine maximum
SolveA
profit.
Updates formulas in calculation sheet depending on X, Y, and
UpdateCalc
time horizon.
SolveB Loops through time horizon values for three scenarios.
Option B Form code Records time horizon shift values.
Navigational Used for navigational buttons.

CS17.5 Re-solve Options


There are two re-solve options for this application: Option A and Option B. For Option A,
the user can change the risk rate and/or time horizon and click the “Re-solve” button to
recall the SolveA procedure. For Option B, the user can click the “Re-solve” button to
recall the SolveB procedure. This procedure again displays the Option B form, which
allows the user to change the shift in time horizon values.

Option A Re-solve
The user can change the risk rate and/or time horizon.
Option
Summary
Option B Re-solve
Allows the user to change the shift in time horizon values.
Option
CASE STUDY 17 Technical Analysis 18

CS17.6 Summary
ƒ The “Technical Analysis of Market Timing” problem seeks to determine values for
X and Y and a max profit for buying and selling shares for a certain time horizon.
ƒ There are four worksheets in this application: the welcome sheet, a calculation
sheet, an output sheet for Option A, and an output sheet for Option B.
ƒ There are four user forms, some controls on the output for the Option A
worksheet, and a few navigational and functional buttons.
ƒ There are several procedures for this application that allow the user to enter
input, perform calculations, view results, and re-solve.
ƒ There is a re-solve option for Option A in which the and Option B.

CS17.7 Extensions
ƒ What other analysis could you add to the output sheets? (Hint: What about charts
and/or graphs?)
ƒ What other scenarios could be considered for Option B?
ƒ Add error checking procedures to all of the form codes. For example, ensure that
only integer numbers are entered for the step size in the Option B form.
ƒ Expand this application to consider more than one stock at a time.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy