Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test 2 #53

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Binary file added .RData
Binary file not shown.
6,385 changes: 6,385 additions & 0 deletions CourseSessions/InClassProcess/MarketSegmentationProcessInClass.html

Large diffs are not rendered by default.

1,064 changes: 1,064 additions & 0 deletions CourseSessions/InClassProcess/nzf_MarketSegmentationProcessInClass.Rmd

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions CourseSessions/Session1/Session1inclass.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Session 1"
author: "T. Evgeniou"
author: "T. Evgeniou really??"
output: html_document
---

Expand Down Expand Up @@ -142,9 +142,9 @@ The correlation matrix does not look pretty for now, but we will see example way

#### Questions

1. Can you find which column asks about the name of the brand rated?
2. Can you find the average rating responded gave to question "`r gsub("_", " ", gsub("\\.", " ", "Q1_3_The.brand.of.boat.I.buy.says.a.lot.about.who.I.am"))`" (note the use of the R command `gsub` in the code to manipulate character strings).
3. *(Extra points)* What is the percentage of male in this population? How many of them responded that they plan to purchase a boat in the future?
1. Can you find which column asks about the name of the brand rated? QN 1_3 & 1_4
2. Can you find the average rating responded gave to question "`r gsub("_", " ", gsub("\\.", " ", "Q1_3_The.brand.of.boat.I.buy.says.a.lot.about.who.I.am"))`" (note the use of the R command `gsub` in the code to manipulate character strings). 3.1135
3. *(Extra points)* What is the percentage of male in this population? How many of them responded that they plan to purchase a boat in the future? 55%, 784 of them
4. *(Extra points)* Explore the R command `table` and use it to present in this report some of the data.
5. Explore the R packages or github repositories you found interesting and prepare to discuss one of them in class, and if possible show some demo.

Expand Down
426 changes: 426 additions & 0 deletions CourseSessions/Sessions23/Session2inclass.Rmd

Large diffs are not rendered by default.

19,532 changes: 19,532 additions & 0 deletions CourseSessions/Sessions23/Session2inclass.html

Large diffs are not rendered by default.

62 changes: 56 additions & 6 deletions Exercises/Exerciseset1/ExerciseSet1.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
---
title: "Exercise Set 1"
author: "T. Evgeniou"
runtime: shiny
output: html_document
---

Expand Down Expand Up @@ -60,6 +61,7 @@ For more information on downloading finance data from the internet as well as on
1. Can you find some interesting finance related R package or github repository?
**Your Answers here:**
<br>
[1. R for Quantitative Finance](https://github.com/cheerzzh/R_for_Quantitative_Finance)
<br>

<hr>
Expand All @@ -83,17 +85,36 @@ pnl_plot(SPY)
#### Questions

1. Notice that the code also downloads the returns of Apple during the same period. Can you explain where this is done in the code (including the .R files used)?
<br>
**Your Answers here:**
<br>
This was defined in the dataSet1.R using the code mytickers = c("SPY", "AAPL"). With this code, Apple stock data is downloaded.
<br>
2. What are the cumulative, average daily returns, and the standard deviation of the daily returns of Apple in the same period?
3. *(Extra points)* What if we want to also see the returns of another company, say Yahoo!, in the same period? Can you get that data and report the statistics for Yahoo!'s stock, too?

<br>
**Your Answers here:**
<br>
The cumulative returns of the AAPL index during this period is `r round(100*sum(StockReturns[,2]),1)`%.
<br>
The average daily returns of the AAPL index during this period is `r round(100*mean(StockReturns[,2]),3)`%;
<br>
The standard deviation of the daily returns of the AAPL index during this period is `r round(100*sd(StockReturns[,2]),3)`%;
<br>

<hr>
<hr>
3. *(Extra points)* What if we want to also see the returns of another company, say Yahoo!, in the same period? Can you get that data and report the statistics for Yahoo!'s stock, too?
<br>
**Your Answers here:**
<br>
Just add the ticket symbol "YHOO" to the dataSet1.R list of tickers to pull.
<br>
For Yahoo
<br>
The cumulative returns of the YHOO index during this period is `r round(100*sum(StockReturns[,3]),1)`%.
<br>
The average daily returns of the YHOO index during this period is `r round(100*mean(StockReturns[,3]),3)`%;
<br>
The standard deviation of the daily returns of the YHOO index during this period is `r round(100*sd(StockReturns[,3]),3)`%;
<br>

### Part II: Simple Matrix Manipulations

Expand All @@ -119,17 +140,27 @@ names(portfolio) <- rownames(StockReturns)
pnl_plot(portfolio)
```


We can also transpose the matrix of returns to create a new "horizontal" matrix. Let's call this matrix (variable name) transposedData. We can do so using this command: `transposedData = t(StockReturns)`.

#### Questions

1. What R commands can you use to get the number of rows and number of columns of the new matrix called transposedData?

2. Based on the help for the R function *apply* (`help(apply)`), can you create again the portfolio of S&P and Apple and plot the returns in a new figure below?

**Your Answers here:**
`r transposedData = t(StockReturns)`
<br>
The number of rows `r nrow(transposedData)` and number of columns is `r ncol(transposedData)`
<br>
Create the new transposed matrix as such:
<br>
```{r echo=TRUE, comment=NA, warning=FALSE,message=FALSE,results='asis',fig.align='center', fig=TRUE}
transposedData = t(StockReturns)
t_portfolio= apply(transposedData,2,mean)
names(t_portfolio) <- rownames(StockReturns)
pnl_plot(t_portfolio)
```
<br>
<br>

Expand All @@ -147,8 +178,10 @@ This is an important step and will get you to think about the overall process on

**Your Answers here:**
<br>
1. Just make sure the code startDate = "2001-01-01" in dataSet1.R is set.
<br>
<br>
2. You can keep adding ticker symbols to the list of tickers you want
<br>

<hr>
Expand Down Expand Up @@ -181,8 +214,12 @@ myData + StockReturns[1:40,]

**Your Answers here:**
<br>

1. I get a value of 20.
It makes not sense but myData is just a lump of dates and data together.
<br>
<br>
2. I should get all sorts of errors since the data doesnt even match up in the dimensions
<br>

<hr>
Expand All @@ -194,11 +231,24 @@ Can you now load another dataset from some CSV file and report some basic statis

<br>

I downloaded the csv of Hilary Clinton and realDonald Trump tweets from Kaggle. It has a lot of text instead of numbers. Link(https://www.kaggle.com/benhamner/clinton-trump-tweets)

You can still do basic analysis of the data like dim but its also has challenges because its mostly text and more advanced functions will be needed to analyze.

```{r eval = TRUE, echo=TRUE, comment=NA, warning=FALSE, message=FALSE,results='asis'}
tweetsData <- read.csv(file = "tweets.csv", header = TRUE, sep=";")
dim(tweetsData)
class(tweetsData)
dim(tweetsData)
nrow(tweetsData)
ncol(tweetsData)
tweetsData[1:2,]
```
### Creating Interactive Documents

Finally, just for fun, one can add some interactivity in the report using [Shiny](http://rmarkdown.rstudio.com/authoring_shiny.html).All one needs to do is set the eval flag of the code chunk below (see the .Rmd file) to "TRUE", add the line "runtime: shiny" at the very begining of the .Rmd file, make the markdown output to be "html_document", and then press "Run Document".

```{r, eval=FALSE, echo = TRUE}
```{r, eval=TRUE, echo = TRUE}
sliderInput("startdate", "Starting Date:", min = 1, max = length(portfolio),
value = 1)
sliderInput("enddate", "End Date:", min = 1, max = length(portfolio),
Expand Down
Loading