Skip to content

Mengungkap Pasar Keuangan (Forex/Stock) dengan News Sentiment Analysis Menggunakan Python – Part #3

Pipeline Model

Yah, kali ini saya ingin berbagi hasil ‘ngoprek” karena rasa penasaran dan keingintahuan saya yang besar pada teknologi kecerdasan buatan dan aplikasinya, khususnya pada dunia finansial.

Apa itu ‘Pipeline Model’?

Pipeline model adalah sebuah pendekatan dalam pengolahan data atau pelaksanaan proses tertentu yang melibatkan serangkaian langkah atau tahap yang dilakukan secara berurutan. Setiap tahap dalam pipeline memproses data atau informasi yang diterimanya, dan kemudian hasilnya diteruskan ke tahap berikutnya. Model ini sering digunakan dalam berbagai bidang, seperti pembelajaran mesin (machine learning), rekayasa perangkat lunak, dan pemrosesan data besar (big data).

Mengapa Kita Membutuhkan ‘Pipeline Model’ pada News Sentimen Analysis?
Pipeline model sangat berguna ketika bekerja dengan dataset yang mengandung kombinasi antara teks dan angka atau numerik. Dimana prapemrosesan kedua data ini berbeda. Data Numerik atau angka, biasanya memerlukan teknik prapemrosesan seperti normalisasi, standarisasi, atau transformasi lainnya untuk memastikan bahwa data numerik berada dalam skala yang tepat dan dapat digunakan oleh model. Sedangkan, Data Teks memerlukan langkah-langkah prapemrosesan yang berbeda seperti tokenisasi, stemming, lemmatization, penghapusan stop words, dan konversi teks menjadi representasi numerik seperti TF-IDF atau embeddings.

The Idea. Ide dari berawal dari hasil pengamatan saya pada website forexfactory.com yang menjadi salah satu situs yang menyediakan News & Calendar secara online dan realtime. Sebagai contoh, lihat Gambar 1 di bawah, dapat kita lihat bahwa akan ada News dengan deskripsi ‘Final Manufacturing PMI‘ dengan impact berwarna merah (yang artinya ‘High Impact’) pada hari Senin 3 Juni 2024, jam 15:45 CET. Kita dapat lihat juga pada kolom ‘Forecast’ dan ‘Previous’ yang masing-masing telah memiliki angka 50.9 dan 50.9, sedangkan untuk kolom ‘Actual’ masih kosong atau belum ada nilainya. Kenapa? Karena memang angka ini akan dikeluarkan tepat pada hari Senin 3 Juni 2024, jam 15:45 CET, yaitu besok. Karena saya menulis artikel ini pada hari Minggu, 2 Juni 2024. Mengerti sampai disini ?

Nah, selanjutnya jika kita lihat pada Gambar 2 berikut dibawah ini, kita akan mengerti lebih dalam tentang sejarah dan detil dari News tersebut. Bahwa News ini adalah event yang rutin diumumkan setiap awal bulannya. Coba perhatikan pada kolom bagian ‘History’ disana terdapat tanggal News tipe ini dikeluarkan atau diumumkan. Dari kolom ‘History’ ini, bedanya, kita dapat melihat semua nilai (Actual, Forecast, Previous). Dan pada kolom ‘Specs’, kita dapat melihat informasi tambahan dan detilnya. Bagian yang menarik pada kolom ‘Specs’ ini bagi saya adalah terdapat informasi ‘Usual Effect‘ yang memberikan indikasi ”Actual’ greater than ‘Forecast’ is good for currency;

Now what ? Dari kedua gambar diatas, saya berkhayal, seandainya saya punya ‘mesin waktu’ sehingga saya bisa melihat ‘future’ atau masa depan. Maka saya akan bisa mengetahui nilai ‘Actual’ dari setiap News yang akan terjadi di masa depan. Dan saya bisa ambil tindakan atau aksi, BUY atau SELL. Mengerti ?

Jadi, saya buatlah sebuah machine learning dengan menggunakan Pipeline model, yang tujuannya dapat memprediksi nilai ‘Actual’ dari setiap News dengan memanfaatkan dataset tersebut.

Saya sudah pernah menjelaskan sedikit tentang ide ini. Kalian bisa menengoknya sebentar, mungkin bisa lebih memahaminya. Monggo…..s’il vous plaît.

Membuat Pipeline Model

Sebenarnya cukup sederhana membuat ‘pipeline model’ untuk keperluan News Analysis ini. Kita cukup definisikan fitur yang menggunakan data numerik dan data teks. Dalam kasus ini, fitur ‘Forecast’ dan, ‘Previous’ adalah data numerik, sedangkan ‘Decription’ adalah data teks. Lalu kita perlu mengkombinasikan kedua fitur tersebut dan mentransformasinya. ‘Preprocesor’, yang dilakukan selama fase pelatihan (training), digunakan untuk mengubah input data. Hal ini memastikan bahwa data baru diproses sebelumnya dengan cara yang sama seperti data pelatihan. Hal ini untuk memastikan konsistensi dengan transformasi data pelatihan.

# Preprocessing for numerical features
numeric_features = ['Forecast', 'Previous']
numeric_transformer = StandardScaler()

# Preprocessing for text features
text_features = 'Description'
text_transformer = TfidfVectorizer()

# Combine preprocessing for numerical and text features
preprocessor = ColumnTransformer(
    transformers=[
        ('num', numeric_transformer, numeric_features),
        ('text', text_transformer, text_features),
    ])

## Neural Network Model
# Preprocessing the training and test data
X_train_transformed = preprocessor.fit_transform(X_train)
X_test_transformed = preprocessor.transform(X_test)

Untuk keperluan project ini, saya membuat sebuah fungsi ‘create_model’ berbasis pada arsitektur Neural Network.

def create_model(input_dim):
    model = Sequential()
    model.add(Dense(128, input_dim=input_dim, activation='relu'))
    model.add(Dropout(0.2))
    model.add(Dense(64, activation='relu'))
    model.add(Dropout(0.2))
    model.add(Dense(32, activation='relu'))
    model.add(Dense(1, activation='linear'))
    model.compile(optimizer=Adam(learning_rate=0.001), loss='mean_squared_error', metrics=['mse'])
    return model

Selanjutnya kita membuat ‘Pipeline model’ dan melakukan pelatihan dengan menggunakan dataset yang ada.

# Create / Update model
model_pipeline = create_model(input_dim)
# Train the model
history = model_pipeline.fit(X_train_transformed, y_train, epochs=10, batch_size=32, validation_split=0.1)

Hasil ? Nah, penasaran dengan hasil ‘Pipeline model’ ini, khan ? Ini saya split hasil dari ujicoba machine learning berbasis Pipeline model ini. Silahkan kalian cek dan ricek ke situs atau website yang ada di dunia maya ini.

                  Description   Currency  Date     Time    Impact Forecast Previous Actual_Pred
27                        CPI m/m  CHF  06-04-2024 06:30:00 High    0.30    0.30    0.27821
31             JOLTS Job Openings  USD  06-04-2024 14:00:00 High    8.37    8.49    6.23451
37                        GDP q/q  AUD  06-05-2024 01:30:00 High    0.20    0.20    0.51078
47 ADP Non-Farm Employment Change  USD  06-05-2024 12:15:00 High  173.00  192.00   84.08122
50                 Overnight Rate  CAD  06-05-2024 13:45:00 High    4.75    5.00    2.29632
66          Main Refinancing Rate  EUR  06-06-2024 12:15:00 High    4.25    4.50    2.66889
69            Unemployment Claims  USD  06-06-2024 12:30:00 High  219.00  219.00  214.80075
91              Employment Change  CAD  06-07-2024 12:30:00 High   27.80   90.40   29.75008
92              Unemployment Rate  CAD  06-07-2024 12:30:00 High    6.20    6.10    5.59385
94    Average Hourly Earnings m/m  USD  06-07-2024 12:30:00 High    0.30    0.20    0.50176
95     Non-Farm Employment Change  USD  06-07-2024 12:30:00 High  189.00  175.00  193.76866
96              Unemployment Rate  USD  06-07-2024 12:30:00 High    3.90    3.90    3.76385

‘Actual_Pred’ adalah hasil prediksi dari machine learning. Kita boleh membandingkan apakah hasil prediksi ini baik/bagus dengan melihat nilai ‘Actual’ sebenarnya.

Kalau kurang jelas, silahkan pake mesin waktu untuk kembali ke Part #1 dan Part #2. 😄😄😄

Bon Dimanche…..Have a nice weekend…..Selamat berakhir pekan.

Colmar, 02 June 2024. Spring.

*Bonus video music cover… 😄😄😄
Please follow and like us:

46 thoughts on “Mengungkap Pasar Keuangan (Forex/Stock) dengan News Sentiment Analysis Menggunakan Python – Part #3”

  1. Hmm it appears like your blog ate my first comment (it was super long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well am an aspiring blog blogger but I’m still new to the whole thing. Do you have any recommendations for inexperienced blog writers? I’d really appreciate it.

  2. Have you ever considered about including a little bit more than just your articles? I mean, what you say is fundamental and all. However just imagine if you added some great images or video clips to give your posts more, “pop”! Your content is excellent but with pics and videos, this blog could definitely be one of the very best in its niche. Good blog!

  3. you are actually a excellent webmaster. The site loading velocity is incredible. It seems that you’re doing any unique trick. In addition, The contents are masterpiece. you’ve performed a magnificent task on this topic!

  4. You’re so interesting! I do not think I have read anything like this before. So wonderful to discover another person with a few genuine thoughts on this issue. Really.. thank you for starting this up. This web site is one thing that’s needed on the web, someone with a little originality!

  5. First of all I want to say excellent blog! I had a quick question in which I’d like to ask if you do not mind. I was interested to find out how you center yourself and clear your mind prior to writing. I have had a tough time clearing my mind in getting my ideas out. I do enjoy writing however it just seems like the first 10 to 15 minutes are usually wasted simply just trying to figure out how to begin. Any suggestions or tips? Many thanks!

  6. Do you have a spam issue on this blog; I also am a blogger, and I was wondering your situation; we have developed some nice methods and we are looking to swap techniques with others, be sure to shoot me an email if interested.

  7. Nice blog here! Also your site loads up fast! What web host are you using? Can I get your affiliate link to your host? I wish my web site loaded up as fast as yours lol

  8. Very good website you have here but I was curious about if you knew of any community forums that cover the same topics talked about in this article? I’d really like to be a part of group where I can get suggestions from other knowledgeable people that share the same interest. If you have any suggestions, please let me know. Many thanks!

  9. This is very attention-grabbing, You’re a very professional blogger. I’ve joined your feed and look ahead to seeking extra of your magnificent post. Also, I’ve shared your website in my social networks

  10. Hiya very nice blog!! Man .. Excellent .. Wonderful .. I will bookmark your site and take the feeds also? I’m glad to find so many helpful information right here in the submit, we’d like develop more strategies in this regard, thank you for sharing. . . . . .

  11. Thank you a lot for sharing this with all of us you really understand what you’re speaking approximately! Bookmarked. Please additionally consult with my website =). We could have a hyperlink trade arrangement between us

  12. I don’t know whether it’s just me or if perhaps everybody else experiencing issues with your website. It looks like some of the text on your content are running off the screen. Can someone else please comment and let me know if this is happening to them too? This may be a problem with my web browser because I’ve had this happen previously. Many thanks

  13. whoah this weblog is magnificent i really like studying your posts. Stay up the great work! You recognize, many people are hunting round for this info, you can aid them greatly.

  14. I was wondering if you ever considered changing the page layout of your site? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or 2 images. Maybe you could space it out better?

  15. My programmer is trying to convince me to move to .net from PHP. I have always disliked the idea because of the expenses. But he’s tryiong none the less. I’ve been using WordPress on a variety of websites for about a year and am anxious about switching to another platform. I have heard very good things about blogengine.net. Is there a way I can import all my wordpress content into it? Any help would be really appreciated!

  16. Nice post. I learn something totally new and challenging on blogs I stumbleupon on a daily basis. It’s always exciting to read content from other authors and use something from their websites.

  17. Hello there! I could have sworn I’ve been to this blog before but after going through a few of the posts I realized it’s new to me. Anyways, I’m definitely pleased I came across it and I’ll be bookmarking it and checking back frequently!

  18. Hi my family member! I want to say that this article is awesome, great written and come with almost all vital infos. I would like to see more posts like this .

  19. Nice weblog right here! Also your web site lots up very fast! What host are you the usage of? Can I am getting your associate hyperlink to your host? I desire my web site loaded up as fast as yours lol

  20. Hello my friend! I want to say that this post is amazing, great written and come with almost all important infos. I would like to see extra posts like this .

Leave a Reply

Your email address will not be published. Required fields are marked *