자산 가격 예측
이제 신경망을 사용해 자산 가격을 예측해 볼 거예요. 이는 정량적 금융 분석과 리스크 관리에서 매우 중요한 작업이에요.
Citibank, Goldman Sachs, J. P. Morgan의 2005–2010년 주가를 사용해 Morgan Stanley 주가를 예측하는 네트워크를 학습시켜 보세요.
입력층 1개, 출력층 1개, 그리고 두 개의 은닉층을 가진 신경망을 만들고 학습시킵니다.
그다음 2005–2010년 동안 Morgan Stanley의 예측 가격이 실제 값과 얼마나 차이가 나는지 확인할 수 있도록 산점도를 표시해요. 예측이 완벽하다면 산점도 점들이 그래프의 45도 직선 위에 놓인다는 점을 기억하세요.
Sequential과 Dense 객체가 제공되며, 2005–2010년 투자은행 주가가 담긴 prices DataFrame도 준비되어 있어요.
이 연습은 강의의 일부입니다
Python을 활용한 정량적 리스크 관리
연습 안내
- 입력 데이터는 Morgan Stanley를 제외한 모든 은행의
prices로, 출력 데이터는 Morgan Stanley의prices만 사용하세요. - 두 개의
Dense은닉층을 가진Sequential신경망model을 만드세요: 첫 번째 은닉층은 뉴런 16개(입력 뉴런 3개), 두 번째 은닉층은 뉴런 8개로 설정하세요. - Morgan Stanley의 가격을 나타내는 뉴런 1개의 Dense 출력층을 추가하세요.
- 신경망을 컴파일하고
model을 학습(fit)시키세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Set the input and output data
training_input = prices.____('Morgan Stanley', axis=1)
training_output = prices['Morgan Stanley']
# Create and train the neural network with two hidden layers
model = ____()
model.add(Dense(16, input_dim=____, activation='sigmoid'))
model.add(____(8, activation='relu'))
model.add(____(1))
model.____(loss='mean_squared_logarithmic_error', optimizer='rmsprop')
model.____(training_input, training_output, epochs=100)
# Scatter plot of the resulting model prediction
axis.scatter(training_output, model.predict(training_input)); plt.show()